I am trying to design a compiler for a language like C# in ANTLR. But I don't fully comprehend the proper order of steps that should be undertaken.
This is how I see it:
- First I define Lexer tokens
- Then grammar rules (with rewrite rules to build AST) with actions that gather informations about classes and methods declarations (so that I can resolve method invocations in the next step)
- Finally, I create "tree grammar" which traverse AST tree and invokes rules that generate the opcodes of (virtual) machine language.
Is this correct? Is the second step's role reading methods' declarations and building AST?
How can I resolve overloaded methods' declarations without build AST ? (backpatching?)