MicroJava is a high-level programming language that is inspired by but simpler than Java.
Like Java, MicroJava programs are compiled into bytecode, which is then executed by a virtual machine (MicroJava Virtual Machine – MJVM).
The MicroJava VM is a simple interpreter-based emulator that executes the generated bytecode.
This project implements a complete compiler for MicroJava, developed as part of the Program Compilers 1 course.
The compiler performs all standard phases of compilation:
- Lexical Analysis
- Syntax Analysis (AST construction)
- Semantic Analysis
- Code Generation (MicroJava bytecode)
The generated bytecode can be executed using the MicroJava Virtual Machine (MJVM).
The compilation process is structured as follows:
- Implemented using JFlex
- Defined in:
spec/mjlexer.lex - Converts source code into a stream of tokens
- Implemented using Java CUP
- Defined in:
spec/mjparser.cupspec/mjparser_astbuild.cup
- Builds an Abstract Syntax Tree (AST)
- Validates grammar structure
- Detects syntax errors
- Implemented using the Visitor pattern
- Generates MicroJava bytecode
- Output file:
.obj
The generated .obj file can be executed using the MJVM interpreter.
