Compilation principle learning experience and suggestions

xiaoxiao2021-03-05  26

Compilation principles are generally considered a difficult course. From the online comment, some people say that I have learned a year and a half software theory, I don't understand it in a compilation; some people even say it is the hardest software course. One; some people complain that the domestic compilation textbook is not easy to understand. From the author's learning practice, the first time I have learned for more than a month, and I have known a half-solution. I learned a week, basically understand the words of lexic analysis. The theoretical part, the grammatical analysis is half solution, the third time I learned to understand the lexical analysis and grammatical analysis. It seems that this class is really difficult. Online posts, write the compiler It is highly unpredictable, it seems to be extremely difficult, very good.

What is the principle of compilation? The author's experience is mainly at these:

1. Mistaken: Many people think that the compilation principle can only be applied to the compiler of the writer language, I feel that the use is not big, the learning is not high. And I may think that the compiler must be written completely.

2. Automatic theory: like NFA, DFA, comparative abstraction, to pay some brain, especially if you have no automatic machine theory when you learn discrete mathematics, it takes more time.

3. Decrection of the agreeds: Mainly some of the closable computments, words that are not good in mathematics, and they will feel effort.

4. LR grammar: mainly introduced automaton

Regardless of the compile textbook, even the absolute classic "Dragon Book" is no exception, it should be involved in these difficulties. Since these content itself does not understand, the author has a big matter, it is difficult to write the writing of the novel. So smoothing.

It is clear that it is difficult to countermere. There are several ways roughly:

1. End awareness: Compilation principle has a wide range of applications in static text processing, a simple example, transforming HTML files into plain text, using compilation principles to achieve "very" simple. Understand the practicality of compilation principle, probably Can improve learning interest.

2. Repeated reading: This method looks the most stupid, it is a basic method. Forget which celebrity said, the book can always be understood.

3. Binding the source code: This is the author Allen Hollub proposal of classic textbook Compiler Design in C. This textbook is characterized by including large section Yacc, Lex code. This is also a good way, and only understand The code can we say that it fundamentally understands theory. Of course, you must completely understand the Yacc code, the workload is very big, and you must first understand theory.

4. Dellation is simple, avoiding light. A "Compilation Principles" (Author Sichuan University, Tang Liang), is basically this idea, and the author avoids the introduction of automatic machine theory and collection. Directly move out the source code, greatly reduced the difficulty of understanding, for grammar analysis, the author introduces the recursive decline and the LL grammar and the corresponding source code, and the LR grammar, only "understand the theory". Although this method avoids Difficulties, but use this method to learn, you can write a typical lexical analyzer and grammar analyzer in a shorter time, which can greatly improve learning enthusiasm.

The author's ideas is generally similar to the fourth approach, but it is slightly different. Due to an accidental reason, the author needs to write a lexical analyzer and grammar analyzer for static analysis of the program source code. Start without starting, hard The scalp looks at the principle of compilation, and it feels difficult. Later, I found a similar open source program, using a compiler called PCCTS to automatically generate tool development, is inspired. Open source is good! I found a name called ANTLR Tool (it is a new version of PCCTS, supporting Java, C and C # code), and downloads a C language syntax file (because the author needs to handle C code files), then you have a small number of action (an action) statement, interface In this way, in this case, it is written in the case of compilation principles (because of understanding because of understanding because of understanding, only the regular expression) is written only for one week. .

This practice makes the author have increased its interest in compilation principles, and re-learned the compilation principle, and summarizes the writing of a practical and effective compilation principle learning step:

1. First use the compiler of ANTLR to generate a tool, do a small program (as the HTML file mentioned above), the required knowledge is only the basic knowledge of regular expressions and the use of tool itself. Method (you can see the online help and online tutorial (tutorial). The benefits of this are:

1) Experience the practicality of the compilation principle and improve learning interest

2) The entry is easy, eliminating the fear of compilation principles learning.

3) Get the sensibility of the lexical analyzer and grammar analyzer, which is beneficial to deepen the understanding of theory.

4) Get the experience of the compiler automatic generation tool (Compiler Compiler) to improve the ability to solve practical problems. (Actually working is not hand-knit but use tools) 2. Tools like Antlr are open source (Open Source) ), You can study its source code so that you should analyze your program if necessary.

3. Go back and see compilation principles. At this time, it will probably find that many theories are easy to understand. There are only a few difficulties left, and it will take a few times, focus on breakthrough.

4. Combine the supplied from the textbook to further deepen the understanding of the teaching materials.

By the way, some compile principles are teaching materials. Some even completely ignore, some even completely ignored, the input subsystem is simply simply more than the lexical analyzer and grammar analyzer. But it is also the foundation of both, so it is necessary to see the source code. In this regard, Antlr's implementation mechanism and LEX are different (of course related to Java and C), which can be viewed.

When I learned VC , I deeply realized the importance of good textbooks. The author started to eat the bad disc version "Textbook" and "21 days of learning VC ", I saw it in the cloud in the cloud, and later I saw "VC technology" "Insider", it is clear that the textbooks of compilation principles seem to be very large, the key is also the right way. The above method author is also a misunderstanding, I hope to have the reference value.

转载请注明原文地址:https://www.9cbs.com/read-36928.html

New Post(0)