I have implemented a C compiler using Flex and Bison as tokenizer and parser. This compiler gets a C language program file as input and provides a MIPS assembly output file. You can also run MIPS output file using QtSpim simulator.
- Flex
- Bison
Flex and Bison are tools for building programs that handle structured input. They were originally tools for building compilers, but they have proven to be useful in many other areas.
You can get and install Flex & Bison tools using the below commands:
sudo apt-get update
sudo apt-get install flex
sudo apt-get install bison
- Unix Text Processing Tools
- What are Flex and Bison?
- Introducing Flex and Bison
- Download QtSpim Simulator
You can clone codes using the below command:
git clone https://github.com/SaraBaradaran/C-Compiler
flex tokenizer.l
bison -d parser.y
gcc parser.tab.c lex.yy.c -o compiler
Finally, you can compile your C program using the below command:
./compiler input.c output.asm