A little insight into the principles of compilation

Source: Internet
Author: User

The compiler principle (compiler Construction) is designed to introduce the general principles and basic methods of compiler construction, including language and grammar, lexical analysis, syntactic analysis, grammar-guided translation, intermediate code generation, storage management, code optimization, and target code generation. It roughly includes two aspects, commonly known as Front end and back end. The official name of the front-end is actually language recognition, also called parsing in engineering. This is actually a wedge point of the entire computer theory. For example, the relatively basic computation theory, which is the theory of studying four basic computational models, is language recognition as the starting tool. And this theory discusses a lot of interesting things:

What method can the computer use to effectively "memorize" the history of how long?
Note that the memory here is state-style, with forgotten memories. Unlike data structures, data structures are memory indefinitely.

A quantitative comparison of the "ability (strength)" of the Computational Model: LL (n), LR (n), LALR, and so on.

Using data structures in parsing and avoiding the trade-off of explicit data structures.

It can be said that learning parsing to learn some computational theory is like learning OS kernel to data structures and algorithms. Although the theory is not strict, but closer to real world. Very interesting.

The back end of code generation, the theory is not mature, so one or two of the initial teaching material is barely allow you to write a full-featured compiler just. To tell the truth, even if you don't read the textbook, it's not difficult to write a target to C compiler after learning parsing.

Some of the benefits of compiling after a theory include:

1, can be more easily understood in a language which writing is equivalent, which is different;

2, can be more objective comparison of different language differences;
3. It is not easy to be fooled by the advocates of a particular language;

4, learning new language is more efficient;

5, in fact, from language A to language B is a common demand, learn how to compile principles to deal with such requirements will be more skilled.

In addition, the compiler principle is a real struggle with the code of the course, for a person who is the pursuit of technology is not to be missed course, and the compilation principle can be said to be a microcosm of computer science. You learn it more is to pursue the nature of the programming language, such as it will be used in register allocation to the greedy algorithm, dead code will be used to eliminate the graph theory algorithm, data flow analysis used in the fixed-point algorithm, Lexical analysis and grammatical analysis of the use of finite state machines and recursive descent such important ideas and so on, perhaps you will not become a compiler developer, but the compilation of the principle of learning to get, what you think is enough to benefit you for life.

On the principle of compiling the study, we should grasp the following points:
Lexical analysis, grasp the regular expression, understand dfa/nfa;

Parsing aspect, can read BNF, know AST, will write simple recursive drop parser, will use ANTLR such parser generator;

Optimization, know how the modern compiler optimization ability, know how to cooperate with the compiler to write efficient and readable code, avoid trying to outsmart compiler;
Implements a simple virtual machine (stack-based, without GC) and translates the arithmetic expression into a virtual machine directive.

Compiling principle is not casually can get started, must face this problem. The learning and practice of compiling principle is usually based on the accumulation of computer compiling process, computer basic working principle and even certain mathematics knowledge, which are distributed and applied to different stages of compiling principle. Based on this, we have the following methods: A. Learn C language, do not require familiarity, but at least to understand the idea of pointers;

B. Learn the data structure, especially on the string/tree/graph related basic processing means to be very familiar with;

C. Learning discrete mathematics, the relevant theory of trees and graphs to be more aware;

D. Learning assembly language, do not require familiarity with the language, but at least to understand the assembly instructions, data between the CPU and memory interaction mechanism;
E. Start to learn the principles of compilation, recommended first to find a domestic university widely used textbooks (such as Hu Yuanyi a compilation principle of the tutorial, very general, but very suitable for the first step), after the introduction (to understand the compiler principle is what to do, to solve what needs) immediately throw away the Dragon book, Tiger Book, Whale book.
Finally, the compiling principle is not only a theoretical course, but also an important part of practice, and only by combining theory with practice can we really learn it well.

A little insight into the principles of compilation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.