This is a creation in Article, where the information may have evolved or changed.
The good text does not say much, the series long wen, everybody waits patiently. Here's the original.
———— Translation Divider Line ————
Compiler (1)-use Go to develop compilers
Overview
I've been interested in how the compiler works for a long time. Mysterious instructions and strange behavior always confuse me. I never really understood how optimization worked, and how the compiler knew what I was doing wrong.
When I decided to learn how to write a compiler, I found a lot of terminology and abbreviations in this area. What is an SLR or LALR parser? What is the damned word bit (lexeme) or finite automaton (finite automata)? What is recursive descent analysis (recursive-descent parsing)? What is an AST?
At the very beginning, it was overwhelming.
The biggest hurdle I've found is that online tutorials, guides, and other learning materials on the Web don't teach you how to write compilers or interpreters. To correct this, they do not teach you how to start from scratch, but only provide an overview of the top-down dependencies of existing tools to accomplish this task. Since building a compiler is really a huge task, it is almost impossible to cover all of the content in a semester's time. I can't blame anyone for that.
Even so, I think these tools have skipped some of the lessons and information that I think are valuable and want to learn more.
Therefore, I hope that through my personal learning how to write a compiler journey, to bring you a guide.
Remember, I'm not an expert programmer, and I'm not figuring everything out. Just really can't help but want to share to everyone, I found such a good content, I hope that we find their own way of learning to help. After all, that's why you're here, isn't it?
Deserved
The calculator is the original work, and all the code about the project is written manually, but it is undeniable that it is similar to the interpreter package in the go and go standard libraries. When I learned how to write compilers, whenever I got stuck, I used to draw on their work. The glory of any code that is similar to their common work should be attributed to Go developers. You can find the source code of the Go compiler in golang.org.
Prerequisite
This series of articles is not very suitable for junior programmers. It assumes that you already have some programming experience and are already familiar with the Go language. Therefore, the target audience should be at least more than intermediate programmers.
Although I think a lot of junior programmers can keep up with the article, I'm not going to explain the go and any other code that isn't directly related to compilation. I'll provide some tool functions, but I won't explain them because they don't have a definite relationship to the compilation.
Tools
The design of the compiler is part of the language design, at least associated. This is a broad topic, and every step of the compiler can be a course.
There are already many tools available for accelerating processing. Flex and Bison are probably the most common open source tools. Flex is based on a program called Lex, which is the abbreviation for Lexical analysis (lexical parsing). Bison is based on YACC and is an abbreviation for yet anther Compiler Compiler (another compiler compiler).
Provides a set of rules that you can create for a GCC front end, or build a compiler of your own. Of course, if you understand what you're doing. If you don't know it, be prepared to blow it.
In fact, I found that skipping these tools to learn basic content would be a lot more fun for others. I think it's better for the long term to build the entire compiler stack by hand, but that's just my personal point of view. You still have to make your own decisions.
The problem with using these tools for me is that, between the stages of compilation, it will eventually become fragmented and lead to runaway. At the same time, there is always a question: "How does this work?" ”
Solution Solutions
That's why, in this series, I'll cover each individual component and start writing code from a bit. This may take longer, but I'm sure you'll have a deep understanding in the end. If you decide to use the tools mentioned above after we have finished, you will feel more relaxed and make more explicit decisions.
Start the second part and get ready to go to work!