Creating JVM language [PART 2] - Minimum theory

March
11th,
2016

At the very top level of abstraction I will need to implement three modules.

Module

Takes

Returns

Lexer

Text (Code)

Tokens

Parser

Tokens

AST (Abstract Syntax Tree)

Compiler

AST

JVM Bytecode

###Lexer
Lexer takes simple text input and tokenizes it. The code is no longer a meaningless stream of bytes, but a list of tokens. Tokens are also associated with type useful for further analysis.
###Parser
The tokens are passed to parser which is responsible for organizaing tokens into hierarchical structure called Abstract Syntax Tree. The tree determines the order in which code should be executed.
###Compiler
Compiler traverses the tree and maps it into valid bytecode instructions.

##Example

Let’s assume I’d like to execute int x=a*5+2; expression. The following steps need to be taken: