Help with Compiler Design [duplicate]
Possible Duplicate:
Learning to write a compiler
I need to come up with a dummy SQL like language which has very limited features. I have never done any compi开发者_StackOverflow中文版ler or parsing stuff before. Can anyone let me know a good point to start may be a link or a example of the same. I am so clueless.
I will be using this dummy language with C/C++ as my primary language.
Thanks
The Dragon Book is often considered a good starting point. However, I will also recommend the ANTLR book
So you want to design a new langauge, build a parser for it, and then translate the result to SQL calls.
You should check out Parser Generators, especially the link to comparision of parser generators
When designing a language, you want the strongest, easiest-to-use parser generator to test your grammars, because you will be changing it a lot. If you choose a weak parser generator, you can find yourself spending more energy reshaping the grammer to make the parser generator tool happy than you will thinking about what grammar makes sense.
But once having a well-defined, parseable language, you discover there is considerably life-beyond-parsing.
When implementing a language, you need to capture an internal representation of it (e.g., a parse tree or AST), find a way to analye it for special cases, and means to transform it to your output language. By and large, parser generator tools don't help you at all here, and yet this is the hard part of the problem. And building all this extra stuff yourself is much more work than most people imagine.
What you actually want is an integrated system of tools that parse, build ASTs, can analyze them, can translate, etc. There aren't many tools like this. Our DMS Software Reengineering Toolkit provides all the machinery you need as foundations. You might not want actually use it, but you should know about this kind of tool so you can make a conscious choice to do it all yourself.
I did a compiler construction course last year and we used the book
Compiler Construction by Kenneth C. Louden
It is very detailed with a good theoretical background. At the same time the author gives enough examples and uses very informative figures, so that you're never lost while learning. Eventually a compiler in C for a toy language is listed in the later chapters.
I really liked it!
精彩评论