This project implements a small compiler pipeline for a toy language called ImpLan and a corresponding stack-based virtual machine (SVM).
The main pipeline is:
- Parse ImpLan source with ANTLR4
- Build an AST
- Build a symbol table and perform type checking
- Generate SVM assembly code
- Assemble SVM code into bytecode
- Execute the bytecode on the SVM
During execution, the program prints the generated AST, the inferred program type, the generated SVM code, and the final result.
- Java (JDK) 8
- Maven 3.x
From the repository root:
mvn -DskipTests packageThis runs the ANTLR generation step and compiles the Java sources.
The entry point is Main.
mvn -DskipTests package exec:java -Dexec.mainClass=Main -Dexec.args="<ImplanFile>"Pass any file containing a single ImpLan program.
mvn -DskipTests package exec:java -Dexec.mainClass=MainThen paste an ImpLan program and finish with an empty line.
- Types:
int,bool,void - Declarations:
- Variables:
type id = exp; - Functions (supports nesting):
type id(type p1, ...) { dec* (stm* exp)? }
- Variables:
- Statements: assignment, function call,
if,while, block{ ... } - Expressions: arithmetic, comparisons, equality, logical operators, unary
-,+,!, and conditional expressions
A program is delimited by outer braces and ends with a final expression whose value is the program result.
Example programs are available in samples.txt.
And one program file in test.implan
src/main/antlr/ANTLR grammars for ImpLan and the SVM assemblersrc/main/java/Java sources (compiler pipeline, AST, SVM assembler/VM)