This is a project I created for learning internals of compilers. The SimplerLang
grammar is taken from this post.
- Open CompilerTest.java
- Run
compile()
- Look for the
output/CgSample.class
generated under root. - To see the source code of
CgSample.class
, use IntelliJ decompiler.
grammar simplerlang;
program : statement+;
statement : let | show ;
let : VAR '=' INT ;
show : 'show' (INT | VAR) ;
VAR : [a-z]+ ;
INT : [0–9]+ ;
WS : [ \n\t]+ -> skip;
- Used a simple grammar to focus more on
compiler phases
rather thanlanguage support
. - Took
ANTLR
generated code as a reference. - Implemented Parse Tree & created Visitable Grammar Nodes.
- Implemented Visitor for writing business logic on Tree nodes.
- Implemented CodeGeneration using
Java ASM
. - Implemented Interpreter & Semantic Analyzer.
Implement Semantic Analyser.Implement custom filename.(Unsupported)Implement Parse Tree.Implement Visitor Pattern.Implement byte code generation
- Lexical Analysis [Done]
- Syntactic Analysis (ie Parsing) [Done]
- Semantic analysis [Done] & Intermediate Code Generation [NA]
- Optimization (optional)
- Code Generation [Done]
Intermediate Code Generation: code gets converted to independent intermediate code. We are not doing this in ck-compiler
.
We could use LLVM
as Backend for implementing this feature.
Do check out other modules in this project for better understanding.️