Skip to content

Vuk-Luzanin/MicroJava-Compiler

Repository files navigation

MicroJava-Compiler

Compilation process

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.


Project Overview

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:

  1. Lexical Analysis
  2. Syntax Analysis (AST construction)
  3. Semantic Analysis
  4. Code Generation (MicroJava bytecode)

The generated bytecode can be executed using the MicroJava Virtual Machine (MJVM).


⚙️ Compilation Pipeline

The compilation process is structured as follows:

1️⃣ Lexical Analysis

  • Implemented using JFlex
  • Defined in: spec/mjlexer.lex
  • Converts source code into a stream of tokens

2️⃣ Syntax Analysis

  • Implemented using Java CUP
  • Defined in:
    • spec/mjparser.cup
    • spec/mjparser_astbuild.cup
  • Builds an Abstract Syntax Tree (AST)
  • Validates grammar structure
  • Detects syntax errors

3️⃣ Semantic Analysis

  • Implemented using the Visitor pattern

4️⃣ Code Generation

  • Generates MicroJava bytecode
  • Output file: .obj

The generated .obj file can be executed using the MJVM interpreter.


About

This project implements a compiler for the MicroJava programming language, covering lexical, syntax, and semantic analysis, as well as bytecode generation. The compiler translates .mj source files into .obj bytecode executed by the MicroJava Virtual Machine (MJVM).

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors