Reputation: 11
As a part of my college project, we're supposed to develop a C compiler. The lexer and parser part is over - the tools Flex & Bison made our uphill task much simpler. Now where we're stuck is that we are unable to move on with the project. How exactly does one proceed once we have these three files in hand:
We also managed to produce an executable by using the following command on the DOS prompt
gcc lex.yy.c y.tab.c -o example1
and i got the executable example.exe... Now how to proceed to get the compiler running? How to get it to build user C code?
Upvotes: 1
Views: 328
Reputation: 120059
You should check whether your example.exe
can read a C program and report any syntax errors.
If it cannot, fix your .y
and/or .l
files and try again.
If it can, great, you have a working parser. Now turn it into a working compiler. Keep adding code, known as semantic actions, to the .y
file, implementing more and more of the compiler's functionality. First, make sure you can report semantic errors, such as invalid types or missing declarations. Then implement assembly code generation.
When the .y
file becomes too big, turn some code into functions and move them to separate .c
files.
Upvotes: 2