Skip to content

Repository files navigation

CPSC 411 Compiler Construction Term Project

Milestone One

Lexical analyzer (scanner) for J-- using ANTLR4.

file: 30205038-cpsc411-milestone1.tex

usage:

  1. SSH into a CPSC Linux machine: ssh <ucid>@cslinux.cpsc.ucalgary.ca
  2. Clone your repo and cd into it.
  3. Run make clean to remove generated files.
  4. Run python3 ~aycock/411/TEST/ms1/run to execute all tests.
  5. Check run.output for results.
  6. Compare with reference: ~aycock/411/j--scan <testfile>

build: make (generates Lexer.py from Lexer.g4)

limitations: ASCII only, no Unicode escapes, decimal integers only.

Milestone Two

Parser and AST builder for J-- using the ANTLR4-generated parser plus ASTShaper.

file: 30205038-cpsc411-milestone2.tex

usage:

  1. Run make clean followed by make to regenerate Lexer.py and Parser.py from their grammars.
  2. Execute python3 ~aycock/411/TEST/ms2/run to rebuild and run the parser tests.
  3. Inspect run.output for the AST listings and success banner.
  4. Compare the AST output with the reference: ~aycock/411/TEST/reference/j--parse <testfile>

build: make

limitations: no semantic analysis; only syntactic validation and AST emission.

Milestone Three

Semantic checker based on cpsc411.ASTTraversal and a stack-of-scopes symbol table. Detects all 17 semantic errors in the specification, annotates AST nodes with sem_type, and reports errors to stderr with line-number context.

file: 30205038-cpsc411-milestone3.tex

usage:

  1. Run make clean followed by make to regenerate Lexer.py and Parser.py.
  2. Execute ~aycock/411/TEST/ms3/run to run all semantic tests.
  3. Check run.output for pass/fail detail and error message listings.
  4. Compare with the reference: ~aycock/411/TEST/reference/j--sem <testfile>

build: make

limitations: treats all integer literals as 32-bit signed; does not perform constant folding for chained unary negation (consistent with reference compiler behaviour).

Final project

MIPS assembly backend: translates the semantically checked AST into MIPS that runs under spim. python3 main.py implements the full pipeline (see main.py and codegen.py).

file: 30205038-cpsc411-finalproject.tex

usage:

  1. Run make clean followed by make.
  2. Compile: python3 main.py <source.j--> > out.s
  3. Run: ~aycock/411/bin/spim -file out.s
  4. Full suite: python3 ~aycock/411/TEST/final/run (from repo root)

build: make

limitations: J-- subset only (see milestones above for lexer/parser/semantics). Codegen spills deep expressions to the stack; getchar uses a read-string syscall workaround for EOF (-1).

About

J-- Compiler in lieu of Compiler Construction with Dr. Aycock

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages