I take the compiler design class, where we have to implement our own compiler (using flex and bison). I had experience in parsing (writing EBNF parsers and recursive descent), but this is the first time I am writing a compiler.
The language design is quite open (the professor left it to us). In the classroom, the professor moved on to generating intermediate code. He said that we do not need to create an abstract syntax tree or a parsing tree during parsing and that we can generate intermediate code as we move.
I found this confusing for two reasons:
What if you call a function before defining it? How can you solve the branch problem? I suppose you would need to make this a rule so that you define functions before using them or perhaps predefine them (e.g. C does?)
How do you feel about conventions? If you have an if-else or even just if , how can you resolve the branch target for if when the condition is false (if you generate the code along the way)?
I planned to create an AST, and then walk around the tree after it was created to resolve the addresses of functions and chain branches. Is this correct or am I missing something?
Vivin paliath
source share