How kaocy/nctu-compiler works
Project type and purpose
• This is a multi‐stage compiler homework suite (projects 1–5), each building on the previous:
• project1: lexical analysis (scanner.l)
• project2: syntax analysis (parser.y + scanner.l)
• project3: adds symbol table construction
• project4: adds semantic/type checking
• project5: adds code generation targeting the JVM via Jasmin
File structure
• Top-level directories: project1 … project5
• Each project contains:
• Makefile (build orchestration)
• .l and .y source files (Flex & Bison)
• C source for helper modules (symbolTable, symtable, codeGenerator)
• test subdirectories with input programs
• project5 also embeds an external jasmin-2.4 toolchain (Java sources + JARs)
README for additional insights
• Confirms grading of each stage
• Notes project5 limitation (unused function return values)
• Scanner (Flex: scanner.l)
• Parser (Bison: parser.y + scanner interface)
• Symbol Table Manager (C modules symtable.c/h or symbolTable.c/h)
• Semantic Analyzer / Type Checker (embedded in parser actions)
• Code Generator (codeGenerator.c/h in project5)
• External Assembler (Jasmin toolchain)
• Driver / Build System (Makefile orchestrating all stages)
• Source .c/.l/.y files → Scanner → token stream
• token stream → Parser → parse tree / AST
• AST → Semantic Analyzer (walks tree, populates symbol table)
• AST + Symbol Table → Code Generator → Jasmin assembly (.j files)
• .j files → Jasmin Assembler → JVM bytecode (.class files)
• Tests feed into the driver, which invokes the pipeline
c. Architectural patterns / design principles:
• Pipeline (linear sequence of compiler phases)
• Modularity: each stage separated into its own directory and module
• Reuse: common .l/.y patterns, shared symbol table interface
d. Technologies / frameworks:
• Flex (lex) for scanner.l
• Bison (yacc) for parser.y
• C99 for parser action code, symbol table, code generator
• Jasmin (Java‐based assembler) for final bytecode emission
• GNU Make for build orchestration