0909 Compilation principle

Source: Internet
Author: User

1. What is the rationale for compiling?

Compiling principle is an important specialized course in computer science, which aims to introduce the general principle and basic method of compiling program construction. The content includes language and grammar, lexical analysis, parsing, grammar-guided translation, intermediate code generation, storage management, code optimization, and target code generation.

2. Why do you learn how to compile?

Compiler theory and technology is essentially an algorithmic problem, of course, because this problem is very complex, its solution algorithm is relatively complex. We learn the data structure and algorithm analysis is also speaking of algorithms, but the basic algorithm, in other words, the introduction of the algorithm, and the compiler principle of this course is to focus on a more focused solution of an algorithm. In the the 1950s, compiler writing has been considered a very difficult thing, the first Fortran compiler said it took 18 years to complete. While people are trying to write compilers, many theories and techniques related to compiling are born, and these theories and techniques are more valuable than the actual compilers themselves. Like mathematicians in solving the famous Goldbach conjecture, although there is no final solution to the problem, but in the course of the birth of many famous books related to number theory.

3. How to learn the principle of compiling?

How to learn the principles of compiling? Individuals are not very recommended to pick up the Dragon book, Tiger Books and so on to see.

Students who have learned the course of compiling principles should have experience, a variety of grammar, various lexical parsing algorithms, very much to kill people's patience and interest; intermediate code generation and optimization is not important in many scenarios (this piece is of course important for the "compiler principle"), and semantic analysis has a lot of detail to deal with. Especially for more complex languages, the final instruction generation, may need to read a variety of manuals, but also more boring.

What is the compiler principle for? Extracting the required information from the source language, translating the source language into the target language, and automatically generating text that satisfies certain specifications ...

There's a thing called DSL (domain-specific language):
Extracting information from data in various formats: xml/json/csv/excel; ....
Conversion of various Rich text: Word/markdown ... Build to pdf/html/.
Write crawlers to capture the content of interest from HTML;
Do website, implement/modify template engine, ORM.
Customize the script that describes the test case specification, and then automatically generate the test case ...
Psychological experiments, according to a simple specification (grammar) to write descriptive sentences, you can generate the relevant scene map;

Recommended two book: "Programming language realization Mode", mainly uses ANTLR to explain various examples. "Field-specific language combat" in Ruby, groovy and other languages to explain. (This kind of book I feel is not very good, I can not find very suitable.) )

Now you've started:
The simplest application, you can put down the lexical, grammatical analysis and other concepts, directly with your language to achieve;
Sometimes you will find that the writing is very "round", although there are a lot of regular expressions;
Then you can try a variety of tools: Yacc/lex, ANTLR, Flex/bison, parsec, ply. With what no need to care, smooth, to achieve the goal on the line. These tools are usually just convenient lexical, grammatical analysis, the semantics of their own processing;
Be dissatisfied with the simple text, want to analyze the true meaning of the program semantics, or want to deeply understand the principles of their own tools, you can go to see those books of the theory;


recommendations from the interpreter:
Basic interpreter, a lot of application scenarios, familiar with the following few is enough.

    • Line interpreter: For very simple "language", in fact, can be parsed by line, edge parsing edge to do semantic processing. As I do a geometry proposition of the DSL, is the specification line to the topic conditions, and then automatically generate problem solving equations;
    • In the lexical and syntactic parsing process of semantic processing, the classic example of "Calculator interpreter" is generally done.
    • Through lexical and syntactic analysis, the abstract Syntax tree (AST) is generated, and then semantic analysis is done based on the AST.

If you are interested in programming language design and implementation, the interpreter is a knack for figuring out many of the concepts that are recommended from scheme learning

    • Recommended The little schemer, another r5r standard is more than 30 pages. Pay attention to hands-on.
    • You can then look at Essential of programming Language and play the various interpreters above.
    • One or two books are not enough, you may not be able to understand many of the concepts when you look at it. To make good use of network resources, more hands-on, choose to read more books is also possible.

4. Thinking: Before you learn the book theory, if you want to write a compiler, what is your idea?

No clue to the compiler.



0909 Compilation principle

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.