A complete compiler implementation for an object-oriented programming language, built incrementally through three phases: lexical analysis, syntax analysis, and intermediate code generation.
This project demonstrates the end-to-end compilation pipeline from source code tokenization to three-address code generation, with proper error handling at each stage.
- Swarnadip Kar (12342210)
- Snehal Suhane (12342100)
The compiler is built in three progressive phases:
Assignment 1 — Lexical Analyzer
Tokenizes source programs using Flex. Recognizes keywords, identifiers, constants, operators, and comments according to the language specification.
Assignment 2 — Syntax Analyzer
Builds on the lexer with a Yacc-based parser. Validates program structure against the grammar and reports syntax errors with precise locations.
Assignment 3 — Intermediate Code Generation
Extends the parser with semantic analysis and TAC generation. Includes a symbol table, type checking, and produces three-address code for valid programs.
compiler-design/
│── Assignment_1_Lexical_Analyzer/
│ │── lexer.l
│ │── sample_input.txt
│ └── README.md
│
│── Assignment_2_Syntax_Analyzer/
│ │── lexer.l
│ │── parser.y
│ │── sample_input.txt
│ └── README.md
│
└── Assignment_3_Semantic_Analyzer/
│── lexer.l
│── parser.y
│── symbol.c
│── symbol.h
│── sample_input.txt
│── sample_error_input.txt
│── Makefile
└── README.md
The compiler handles a variant of an object-oriented language with:
- Primitive types: int, double, bool, string
- Arrays with dynamic allocation
- Classes with single inheritance and interface implementation
- Functions and methods
- Control flow: if-else, for, while, do-while
- Standard operators with C-like precedence
- Single-line and multi-line comments
Each assignment is self-contained with its own build instructions. Navigate to the respective directory and follow the README.
Example for Assignment 3:
cd Assignment_3_Semantic_Analyzer
make test
Detailed compilation and execution steps are provided in each assignment's README.
- Flex (lexical analyzer generator)
- Bison / Yacc (parser generator)
- GCC or compatible C compiler
| Phase | Status | Key Deliverables |
|---|---|---|
| Lexical Analysis | Complete | Token recognition, whitespace handling, error detection |
| Syntax Analysis | Complete | Grammar validation, parse tree construction, error reporting |
| Semantic Analysis & TAC | Complete | Symbol table, type checking, three-address code generation |
- Each assignment builds on the previous one but can be tested independently.
- All phases include error handling with line/column information.
- The final TAC generator (Assignment 3) supports only the main function for simplicity.