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:
- F开发者_StackOverflow社区irst 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?)
Have a look at Language Implementation Patterns it explains how to create your own languages (both interpreted and byte-code/VM-like). At the moment, your questions are too broad, and I don't think anyone is able to post an answer in a forum that explains all the details of how to create your own language from start to finish.
Feel free to ask more specific questions when you have them, of course.
Good luck!
精彩评论