What knowledge is required/recommended before approaching compiler development?

StackOverflow https://stackoverflow.com/questions/7667322

  •  07-02-2021
  •  | 
  •  

質問

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. 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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top