Java – Creating a very basic compiler using Java

compilerjavamachine-codeprogramming-languages

I want to try and create my own very basic language, with it's very basic compiler. All using Java.

For now, it will only need to enable to 'programmer' to print things to the screen.

I had an idea for how to do this, and what I wanted to know is: Will this be considered an actual 'compiler', an actual 'language', and an actual 'virtual machine'? (All very, very basic of course).

My idea was to create a program which will serve as the 'IDE' (editor and compiler), and another one which will serve as the 'virtual machine'.

This means that the IDE will not compile the written code to some existing machine code, like the Java Bytecode, but will actually compile to some kind of compiled code made up by me.

This compiled code will only be understandable by my 'virtual machine' program, and will only be able to run inside this program. The 'virtual machine' program, will use high-level Java operations in order to understand and execute the compiled code.

The 'virtual machine' program will be a Java program, running on the JVM.

My question is: Conceptually, is this considered a virtual machine, and 'machine code'?
If not, is this still considered a 'programming language', even though it's compiled bytecode can only run inside a specific program?

Best Answer

Sure it is. Everything that introduces another level of interpretation into the computing stack is a virtual machine that a programmer can target. It may not become a very complete or successful one unless you put insane amounts of effort into it, but your claim to the technical term is valid.

"Machine code" is a more restricted term. Surprisingly, the convention is not to call code that runs on a virtual machine "machine code", but "byte code". "Machine code" is usually understood to mean code to be run on a physical microprocessor, i.e. a stream of its opcodes. Anything below that is micro code, and anything above is either "byte code" or just "code" (Java code, Python code, etc.)