Necessary software Architect-compiler principles & #183; syntax

Source: Internet
Author: User

Recent soft tests. I watch the video of the process!

Found inside there is a lot of content already in self-good contact process. and accounted for 80% of the ratio!

But part of it. I'm a strange part of it. Research, here, the content of my research to share to everyone!


Compiler principle:

First of all, I saw him at first sight. Think that this is a special magic of scientific knowledge!

There should be very many difficulties in it. But. My wish reached, the first two books are a little foggy feeling. But with the depth of contact, video, books, network three aspects of the joint attack, this magical thing, become not magical.

The development of programming languages. We just introduced more. Want to know, be able to see this site "programming language development history". We are all clear that today we use Java, the third-generation programming language, to be able to program using a familiar way of thinking, in which we go through a lot and compile the principle. We can understand this simply:

The earliest not in the sense of the compiler, once people directly face the computer code, is to punch the hole to play tape programming. The mainframe runs the program by reading the tape.



Because the machine language is composed of 0 and 1, it is difficult to read. So on the basis of machine language developed the assembly language. Because assembly language is still very difficult to use, so developed a high-level language.

It can also be foreseen that the first high-level language compiler was written in assembly language.

And compiling is exactly the inverse of the process, we look at a table:


This is the basic process of compiling principle, the middle code is approximate assembly language. and the target program is machine-recognizable 0 and 1.


Grammar:

Like we write a blog, we write something to want to communicate, must be in accordance with a certain format to write, I write in English format without learning English people, like the Heavenly Book, the compilation of the grammar, and this similar, we have to follow certain rules of lexical analysis and grammar analysis, And one of the basis of this is today's leading character grammar!

We know. Before 0 and 1, the code is basically a meaningful statement of some characters. And compiling is to take them step by step disassembly into the computer can understand the process of the statement, here is derived from a concept, is the end of the non-terminator!

Terminator: No disassembly in the program, the meaning of the statement ends here. Representation: Letter Lowercase
Non-Terminator: can also be disassembled in the program, the statement includes multiple meanings, the expression form: uppercase letters


And we graded the grammar so that the computer could infer how much of our statement was broken down. Or what structure of the statement he is.


Type 0 Grammar

Set G={vt,vn,s,p}, assuming that each of its production α→β is such a structure: α∈ (VT∪VN) * and at least one non-terminator, and Β∈ (VT∪VN) *. Then G is a type 0 grammar.

Type 0 grammar is also called phrase grammar. A very important theoretical result: the ability of type 0 grammar is equivalent to Turing (Turing). Or, no matter what 0 type language is recursive enumerable, conversely, the recursive enumerable set is necessarily a 0-type language. Type 0 Grammar is one of the least restrictive of these types of grammar. So at least it is the type 0 grammar that is generally seen.

Type 1 GrammarThe Type 1 grammar is also called context-sensitive grammar, which corresponds to a linear bounded self-active machine.

It is based on the type 0 grammar of each α→β, there are |β|>=|α|. The |β| here represents the length of the beta.



Note: Although |β|>=|α| is required. But there is one exception: α→ε also satisfies type 1 grammar.
If there is a->ba, the |β|=2,|α|=1 conforms to the Type 1 grammar requirements. Conversely, such as aa->a, it does not conform to type 1 grammar.

Type 2 Grammar The Type 2 grammar is also called context-independent grammar, which correspondingly pushes itself to the active machine. Type 2 grammar is based on the Type 1 grammar. Re-satisfies: Each α→β has an alpha non-terminator.

such as A->ba, in line with type 2 grammar requirements.
such as Ab->bab, although conforming to type 1 grammar requirements, but does not conform to the requirements of type 2 grammar, due to its α=ab. And AB is not a non-terminator.


Type 3 Grammar Type 3 grammar is also called normal grammar, which corresponds to the finite state of its own active machine. It is based on the Type 2 grammar: a→α|αb (right linear) or a→α| Bα (left linear).


If there is: A->A,A->AB,B->A,B->CB. Conform to the requirements of type 3 grammar. However, the hypothesis is deduced as: A->AB,A->AB,B->A,B->CB or deduced as: A->A,A->BA,B->A,B->CB does not conform to the requirements of type 3 method. In detail, the sample A->AB,A->AB,B->A,B->CB in the A->ab does not conform to the definition of type 3 grammar, assuming that the back of the AB, changed to "a non-terminator + a Terminator" form (that is, AB) on the right.

In the example A->A,A->BA,B->A,B->CB, it is assumed that the B->CB should be changed to B->BC form. Due to A→α|αb (right linearity) and a→α| Bα (left linear) two sets of rules cannot come out at the same time. Now, in one grammar, only one of them can be fully satisfied, and the ability to count 3 grammar.


Supplement: Type 0 Grammar includes 1, type grammar, type 1 grammar including 2, type grammar, 2 grammar including Type 3 grammar


Summary

The grammar and the knowledge we have lifted are actually very much connected, for example, we did not learn a language. We found. The underlying content is all the same, as long as writing different code styles varies, we call it syntax, and we infer that this is Java writing code or C # writing code. Sometimes the difficulty is that syntax is a set of prescribed formats, and if only this lattice is composed, that is, Java writes code. So. Compile syntax, is a standard. According to the standard, we ask what is. So, this is not a good understanding of it?

Necessary software Architect-compiler principles & #183; syntax

Related Article

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.