How khuethuc/co3005-ppl-hk232 works
Main Components
• Input (ZCode source code) – starting point
• Lexical Analyzer (Lexer) – based on ANTLR (you see files and directories such as .antlr, ZCodeLexer.py, tokens, etc.)
• Parser – the parser is generated using the provided grammar (ZCode.g4) and includes ANTLR listener, visitor, and error modules.
• AST Generation – seen in assignment2 and later (files like ASTGeneration.py and AST.py); this is responsible for constructing the program’s AST.
• Static Checker – found in assignment3 and assignment4 (StaticCheck.py, StaticError.py) that performs semantic analysis.
• Code Generator – present in assignment3 and assignment4 (CodeGenerator.py, Emitter.py, Frame.py, MachineCode.py) to translate the AST into intermediate or target code.
• External Dependencies – note the presence of an external jar (jasmin.jar) which likely is used in assembling or further processing the generated code.
• Testing and Utilities – there are extensive test suites (LexerSuite, ParserSuite, ASTGenSuite, CheckSuite, CodeGenSuite, etc.) and supportive utility files.
Relationships and Data Flow
• Flow proceeds to the Lexical Analyzer that tokenizes input using ANTLR-generated components.
• Tokens then feed into the Parser, which builds a parse tree.
• An AST Generation phase walks the parse tree and constructs an abstract syntax tree.
• The AST flows to the Static Checker to ensure that semantic rules are satisfied.
• Upon passing semantic analysis, the AST is handed to the Code Generation phase to produce lower-level or machine code (with jasmin.jar assisting if assembly is required).
• Testing modules exist separately (under src/test and target/test) to validate each phase.
Architectural Patterns & Design Principles to Highlight
• Pipeline Pattern: The compiler’s phases (lexing, parsing, AST generation, static checking, code generation) directly follow one another in a pipeline.
• Layer Separation: Clearly distinct modules for each compiler phase, with well-defined responsibilities.
• Modularity: Each assignment directory reinforces unit testing and modular development. The use of ANTLR for the language front-end and external libraries for code generation (jasmin.jar) is also an architectural choice.
• Iterative Development: Multiple assignments indicate an evolution of the project where each component is refined over time.