A compiler front-end implemented in C for a custom programming language, supporting lexical analysis, grammar-based parsing, token generation, and syntax validation.
This project was developed as part of a compiler construction course and focuses on building core components of a language-processing pipeline from scratch.
- Lexical analysis for tokenizing source code
- Comment removal utility
- Token list generation with line numbers
- Grammar-based parsing using FIRST and FOLLOW sets
- Predictive parsing using parse table construction
- Syntax checking for input source programs
- CPU time measurement for lexer and parser execution
driver.c– Menu-driven entry point for running compiler functionalitieslexer.c,lexer.h,lexerDef.h– Lexical analyzer implementationparser.c,parser.h,parserDef.h– Parser implementationGrammar.txt– Grammar specificationFirst.txt– FIRST setsFollow.txt– FOLLOW setsNTerminals.txt– Non-terminal definitionstokenId.txt– Token mapping/referencet1.txttot6.txt– Sample test casesmakefile– Build instructions
Compile the project using:
make
This generates the executable:
stage1exe
Run the compiler front-end with:
./stage1exe <input_file> <output_file>
Example:
./stage1exe t1.txt output.txt
After running the executable, choose from:
0– Exit1– Remove comments and print cleaned code2– Print token list3– Check syntactic correctness of the input source code4– Print total time taken by lexer and parser
- DFA-based lexical analysis
- Token recognition and symbol handling
- Grammar representation
- FIRST and FOLLOW set computation
- Predictive (LL) parsing
- Parse table construction
- Syntax validation
The program can:
- Print lexemes and token names with line numbers
- Validate syntactic correctness of input programs
- Generate parser-related output files
- This project focuses on compiler front-end design (lexing + parsing), not code generation
- Grammar and parsing data are loaded from external text files
- Sample test inputs are included in the repository
Developed collaboratively as part of a compiler construction course at BITS Pilani.