This project implements a C to MIPS compiler using 3-address code (3AC) as an intermediate representation.
Assignment4/
βββ src/ # Source code directory
β βββ scanner.l # Lex file for lexical analysis
| βββ parser.y # File for syntax analysis and generation of 3AC
| βββ codegen.cpp # File for generation of MIPS code from 3AC
βββ include/ # Auxillary directory
β βββ 3AC.h # header file for 3AC code generation
| βββ functions.h # Auxillary functions for 3AC code generation
| βββ utility.h # Data Structures definition for nodes
βββ test/ # Test cases for the compiler
β βββ input1.c # Sample test case 1
β βββ input2.c # Sample test case 2
β βββ input3.c # Sample test case 3
β βββ ... # More test cases
βββ output/ # Stores output files (Auto-generated)
β βββ output1.s # Output of input1.c
β βββ output2.s # Output of input2.c
β βββ output3.s # Output of input3.c
βββ Makefile # Build automation file
βββ run.sh # Script to execute test cases
βββ README.md # Project documentation
Follow these steps to build and execute the lexical analyzer:
make clean
makeAfter that run script using:
./run.shls output/ # Lists all output files
cat output/output1.s # View output for input1.c
cat output/output2.s # View output for input2.cErrors for each code are written within the generated output file corresponding to that code.
- Lexical Analysis: Uses Flex (Lex) to tokenize C source code.
- Parsing:
Uses Bison (Yacc) to parse the tokenized code according to standard C grammar.
Each of the output files contain symbol table and constant table generated after parsing.
- Intermediate Representation: Uses Three address code.
- Compiler Backend: Generates MIPS Assembly Code to be run on a simulator like Qtspim
- Ensure that flex, bison, Qtspim and g++ are installed before running the project.
- The project is structured to automatically generate output files in the output/ directory.