This project is a fully functional mini C compiler developed from scratch using:
- Flex for lexical analysis
- Bison for syntax parsing
- C for compiler logic and semantic analysis
It is designed to parse a subset of the C language and includes a full pipeline from tokenization to semantic analysis and AST evaluation.
- Lexical Analysis using Flex
- Syntax Parsing with Bison (LALR parser)
- Abstract Syntax Tree (AST) construction and traversal
- Symbol Table Management for scoped variables and function identifiers
- Type Checking for expressions, assignments, and operations
- Undeclared Variable Detection
- Function Declaration & Call Validation
- Error Handling with informative messages
- AST Evaluation & Visualization Support
Install the following dependencies:
sudo apt update
sudo apt install flex bison gcc build-essential git -y
make
./compiler test.c
This will parse test.c and perform lexical, syntax, and semantic analysis.
This project uses a .gitignore file to exclude automatically generated files from version control, ensuring a clean and portable codebase. Ignored Binary and Generated Files:
- compiler — The compiled output binary.
- *.o — Object files generated during compilation.
- lex.yy.c — File generated by Flex.
- parser.tab.c, parser.tab.h — Files generated by Bison.
These files are regenerated automatically when you run the make
command, so they do not need to be tracked in the repository.