PROJECT NOTES / COMPILERS & LANGUAGES
SPL Compiler
From language to structure.
An educational Scala and Java compiler frontend with JFlex scanning, CUP LALR(1) parsing, reference-matched ASTs and scoped semantic type checking.
- Scala
- Java
- JFlex
- CUP
- Compiler Design
- Type Checking
Coursework source withheld pending publication permission; no public repository link is claimed.

THE CONTEXT
A closer look.
The problem
SPL is a statically typed teaching language with nested functions, records, tuples and arrays. A compiler must distinguish valid token sequences from well-formed syntax and then enforce meaning through scopes and types. Each phase needs evidence of its own correctness.
What I built
I developed JFlex lexer specifications and a CUP LALR(1) grammar that constructs Scala abstract syntax trees. Grammar precedence resolves operator grouping and dangling-else cases. The inspected implementation includes scoped symbol tables and semantic type checking. Its AST output was compared with the supplied reference compiler on all 15 test programs and matched each one. Complete IR generation is not claimed: the inspected Code.scala still contains unfinished phase-5 cases.
TOOLS & ENGINEERING
Built with.
- Scala
- Java
- JFlex
- CUP
- Compiler Design
- Type Checking
- Lexical Analysis
- Syntax Analysis
- Context-Free Grammars
- LALR(1) Parsing
- Abstract Syntax Trees
- Semantic Analysis
- Symbol Tables
- Scope Management
- Grammar Precedence
- Maven
- Automated Testing
Verified lexer, parser, AST and semantic-analysis work. All 15 AST comparisons passed; complete intermediate-representation generation remains unfinished.
HOW IT FITS TOGETHER
The architecture.
- SPL source · original demonstration
- JFlex · lexical analysis
- CUP · LALR(1) parsing
- Scala AST · 15 reference matches
- Scoped symbols · semantic checking
- IR scaffold · incomplete generation
- 01
JFlex turns the original SPL source into tokens, including identifiers, literals, keywords and operators.
- 02
CUP applies an LALR(1) grammar with explicit precedence and constructs a typed Scala AST.
- 03
AST nodes represent nested functions, records, tuples, arrays, expressions and control flow. Fifteen reference comparisons validate this frontend phase.
- 04
Scoped symbol tables support semantic analysis. A valid sample passes phase 4; an incompatible string-to-integer declaration is rejected.
- 05
IR scaffolding includes static-link traversal, activation-record layout, heap allocation and control-flow forms. Phase 5 fails on the original demonstration program, so end-to-end IR generation remains incomplete.
OBSERVED OUTPUT, NOT A MOCKUP
From the actual compiler.
STAGE 01
Original SPL input
var total: int = 3;
print(total + 4);STAGE 02
Generated AST · phase 3
Program(BlockSt(List(VarDef("total", IntType(), IntConst(3))),
List(PrintSt(List(BinOpExp("plus",
LvalExp(Var("total")),
IntConst(4)))))))STAGE 03
Semantic check · phase 4
View complete type-check trace
** BlockSt(List(VarDef(total,IntType(),IntConst(3))),List(PrintSt(List(BinOpExp(plus,LvalExp(Var(total)),IntConst(4))))))
** VarDef(total,IntType(),IntConst(3))
** IntConst(3)
-> IntType()
->
** PrintSt(List(BinOpExp(plus,LvalExp(Var(total)),IntConst(4))))
** BinOpExp(plus,LvalExp(Var(total)),IntConst(4))
** LvalExp(Var(total))
** Var(total)
-> IntType()
-> IntType()
** IntConst(4)
-> IntType()
-> IntType()
->
->STAGE 04 / EXPECTED REJECTION
Invalid program rejected
var total: int = "three";
*** Typechecking Error: Incompatible types in variable declaration: VarDef(total,IntType(),StringConst(three))
*** Symbol Table: List(List())ENGINEERING DETAILS
Decisions that matter.
Parsing with deliberate precedence
The lexer and parser are generated from JFlex and CUP specifications. The grammar encodes operator precedence and handles dangling-else grouping; AST comparisons check the resulting structure rather than screenshots alone.
Scopes and semantic checks
Symbol-table scopes track declarations and function parameters. The independently run examples demonstrate accepted integer arithmetic and a rejected incompatible variable declaration.
What the verification proves
All 15 supplied programs produced phase-3 ASTs matching the reference output after whitespace normalization. This is an AST-equivalence result, not a claim that all compiler phases or generated machine code passed 15 tests.
IR work has a visible boundary
The codebase contains frame, static-link, allocation and control-flow infrastructure, but missing cases prevent complete IR output for the sample. The case study shows the working frontend and type checking without presenting the reference implementation as student-generated IR.
Coursework and publication
The inspected GitHub repository is private and empty; usable local source was inspected instead. Instructor reference binaries, assignment inputs and implementation code are withheld while publication permission is unresolved. Only original demonstration input, actual output and aggregate verification results are shown.
Built from the existing local SPL project using Maven and Java 8, with student implementations selected rather than reference-solution switches. Evidence was captured from real command output; no terminal result or successful IR output was invented.
UP NEXTpH Measurement System