Mini Compiler - CS F363 (Python)
Compiler construction project for CS F363, designed as a step-by-step implementation of core compiler phases.
The goal was to build the full pipeline step by step:
- Lexical analysis
- Syntax analysis
- Semantic analysis + symbol table
- Intermediate code (TAC)
- Basic optimisation + pseudo assembly
| Phase | Status |
|---|---|
| Lexical Analysis | Implemented |
| Syntax Analysis (Recursive Descent + AST) | Implemented |
| LL(1) Parser Evaluation | Implemented |
| SLR(1) Parser Evaluation | Implemented |
| FIRST/FOLLOW + Parsing Tables | Implemented |
| Symbol Table with Nested Scopes | Implemented |
| Semantic Analysis | Implemented |
| TAC Generation | Implemented |
| Optimization | Implemented |
| Target/Pseudo Assembly Generation | Implemented |
Source Program
|
v
Lexer
|
v
Token Stream
|
v
Parser (AST)
|
v
Symbol Table (Scoped Bindings)
|
v
Semantic Analyzer
Supporting parser-evaluation path:
- LL(1) stack trace
- SLR shift/reduce trace
- FIRST/FOLLOW and table construction materials
compiler.py- main entry point (menu-driven compiler runner)README.md- project overview and run/demo guidecontribution.md- team contribution details
lexical_specification.md- formal lexical specification artifact
00_overall_compiler.md01_lexer.md02_parser.md03_grammar.md04_symbol_table.md05_compiler_driver.md06_semantic_analysis.md
evaluation_program.txt- official evaluation programdemo.txt- integrated demo programQ1_Lexical/...Q8_Optimization_TargetCode/- question-wise categorized tests
tokens.py- token enums + error/report dataclasseslexer.py- lexical analyzer (regex-based scanner)parser.py- recursive-descent parser + AST node modelgrammar_utils.py- CFG, FIRST/FOLLOW, LL(1)/SLR table generationll1_parser.py- LL(1) parser with traceslr_parser.py- SLR parser with tracesyntax_analyzer.py- CFG/derivation/parse-tree display utilitiessymbol_table.py- AST-driven scoped symbol tablesemantic_analyzer.py- semantic checks using AST + symbol tabletac_generator.py- planned module (not implemented yet)optimizer.py- planned module (not implemented yet)target_codegen.py- planned module (not implemented yet)
Run with default source:
python compiler.pyRun with explicit file:
python compiler.py testPrograms/evaluation_program.txtUse this sequence during viva/demo:
- Run
testPrograms/evaluation_program.txt - Option
2-> token stream - Option
3-> AST - Option
1-> lexical/syntax/semantic summary - Option
8-> symbol table trace + scoped tables - Options
4,5,7-> LL(1)/SLR traces + FIRST/FOLLOW/tables - Option
9-> TAC - Option
10-> optimize target code
Error-case demonstration:
- Syntax errors:
testPrograms/Q3_SyntaxErrors/ - Semantic errors:
testPrograms/Q6_Semantic/
- Shambhavi Jha [2023A7PS0009U]
- Venkata Shreya Vella [2023A7PS0096U]
- Yuvaraj Nayak [2023A7PS0006U]
- Krishna Nagpal [2023A7PS0321U]