This is the frontend of a compiler for a subset of C. The stages of the compiler implemented are lexical, syntax, semantic phases and intermediate code generation. It includes support for the datatypes int
and char
. Conditional statements that are supported are if-else
. Support is also provided for the while
iteration statement. All the basic error checking for each of the three phases is implemented.
The tools used for building this compiler are flex
for the lexical phase and yacc
for the remaining phases.
The tools can be installed with the commands
sudo apt-get install flex yacc
Navigate to the root directory of the repository. To run the compiler on a source program, say test.c, run the following command:
./compile test.c
The output is a sequence of three address instructions equivalent to the input C program.