开发者

What knowledge is required/recommended before approaching compiler development?

There is a question on stackoverflow about Learning to write a compiler. I have looked at it and I think it's an undertaking I want to tackle. I think (like many others) the knowledge will be invaluable to a programmer. However, my skills are primarily in C++ and I would say I am very comfortable with the syntax of the language and some basic algorithms and design concepts, but I am by no means a seasoned programmer. 开发者_C百科My only programming experience comes from academic textbooks at the college level and the completion of introductory/intermediate courses (300 level classes). Hence, the rise of my question.

With only a general knowledge of the C++ language and no Assembly knowledge, would a book aimed at the theories and workings of a compiler and the implementation of those theories, such as the book Compilers: Principles, Techniques, and Tools (2nd Edition), be difficult for me to understand?


I would recommend you start with an interpreter first as you don't need proprietary hardware knowledge to implement it. The key concepts are usually how is the language defined, what makes a statement, building parse trees, etc... The hardware knowledge to me is secondary than actually understanding how to read and evaluate the statements.

What I did when learning was write a small interpreter for a Pascal like language and started small with simple statements and variable storage and slowly added different things to it as I got better.


Go ahead - it's a great way to learn. Often, you will need to try out techniques given in the book before you really understand them, but after you go through the exercise you should be a better programmer overall.


You will need to learn some kind of assembly language (or byte code) in order to translate a compiled program into something that can actually be executed.

For C(++) in particular you'll also need a copy of the C(++) standard(s).

You can make a few short cuts like interpreting instead of compiling fully or translating into a different language and compiling that with a different compiler.

Also, you should consider first making a compiler for a small or dumbed down language like Forth, Basic or so-called small C (not supporting all types, constructs and keywords and lacking most of the standard library).
I can estimate that it would take me, a fairly versed C programmer, who knows x86 well, a few months (~3) to make a working small C-ish compiler. Just that, minimal standard library, no optimizations, minimal error checking (that is, not generating all the useful warnings). This is to give you an idea of how long things can take even in not so complex cases. Making quickly something small can be more rewarding.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜