Overview
Alan is a small imperative teaching language: byte/int/reference/proc types, functions, if/else, while, strings, and a runtime library of built-ins. This project is a complete compiler for it — from source text to executable JVM bytecode.
The hardest decision was also the most satisfying: instead of emitting Java source and letting javac finish the job, the compiler emits JVM bytecode directly with the ASM tree API (ClassNode, MethodNode, InsnList). That means every phase of a real compiler had to work.
What I built
A classic three-stage pipeline:
- Lexing — a JFlex grammar (
lexer.jflex) covering keywords, hex and string literals,--comments, with line/column tracking. - Parsing — a CUP LALR grammar (
parser.cup) with operator-precedence declarations, building a typed AST (Program,FuncDef,Expr,IfStmt,WhileStmt,Assignment…). - Semantics and code generation — a
SymbolTable/SymbolEntrystack with full type checking (SemanticException,TypeException), thenIRGen/CompileContextwalking the AST into ASM bytecode. AMemHeapmanages memory layout and alibrary/package provides runtime intrinsics (ReadInteger,WriteString,Strcmp,StringToArrayList).
The delivery includes Maven build scripts and shell tools for syntax check, semantic check, compile and execute — with working example programs: hello_world, bubble sort, Hanoi towers, primes, string reversal.
Technical highlights
- Complete pipeline: lexer → parser → typed AST → JVM bytecode, nothing stubbed
- Direct bytecode emission via ASM — no source-level round trip
- Symbol tables, type checking and runtime library for a full language
Outcome
Real Alan programs compile and run on the JVM. Of all the technical work I have done, this one gave me the most: it is demanding, precise, and deeply enjoyable.