Lesson Chapter summary

First, sort out the contents of the second chapter, understand and write a summary.

1. the intuitive notion of grammar

In natural language, for example, people can not list all of the sentence, but it may give some rules of sentence structure. Chinese sentence can be made with the predicate of the subject, a verb constituting a predicate and object directly, using EBNF chapter represent this configuration rule. Examples are as follows:

<Sentence> => <Subject> <predicate>

=> <Pronoun> <predicate>

=> I <predicate>

=> I <verb> <direct object>

=> I <direct object>

=> I am a university student

Wherein => the meaning of using a rule, a symbol representative of its left end, the right end of the symbol string is generated.

2 . Symbols and strings

(1) alphabet

The alphabet is a nonempty finite set of elements, called symbol alphabet elements, and therefore also known as the symbol alphabet set, different languages ​​have different alphabets, e.g. characters, figures, etc.

(2) a symbol string

Symbols from the alphabet of any finite sequence called a string, allowing free symbol string, denoted by E, a length of 0, i.e. |. E | = 0.

3. The formal definition of grammar and language

    Rules are also called rewrite rule, production or formula, shaped like a-> B or a :: = B (a, B) ordered pair, which is called a left portion, B is called a right portion

Grammar G is defined as a four-tuple (Vn, VT, P, S ), wherein the non-terminator Vn,; VT as the terminator; P rule (a-> B) is set, a ∈ (V n- the UV T ) * and comprises at least one non-terminal symbol,

B ∈ (V n- the UV T ) * ; V n- , V T and P plenty of non-poor set, S is the start symbol identifiers or referred to, it is a nonterminal.

4. grammar type

Grammar is divided into four types, i.e., 0 or type, called type 1, or the context sensitive grammar, or type 2, said context-free grammar and type 3 grammar or said regular grammar. The difference between these types of grammar that impose different restrictions on production.

Let G be a grammar, S is the start symbol of the grammar, abo G is a sentence in the grammar. If there S- * → aAo and (A- + → b subscript b is measured with respect to the sentence abo nonterminal A phrase particular, if (A → β is abo sentence with respect to the rule A → b direct phrases (also known as simple phrase). Right sentence a phrase called directly handle of the sentence. the concept is only suitable to handle the right sentence

The context-free grammar and syntax tree

Describes a simple assignment statement is generated Formula

<Assignment statement> -> i: = E

Grammar fragment described conditional statement

<Conditional statements> -> if <condition> then <statement> | if <condition> then <statement> else <statement>.

  [Alpha] at any step derivation => β, where α, β is a sentence of [alpha] is the leftmost (rightmost) nonterminal replaced, this derivation is called leftmost (rightmost) derivation, where the rightmost derivation also known canonical derivation.

  For there is a sentence of two courses corresponding to different syntax tree, then the grammar is ambiguous, in other words: there is a grammar of a sentence, he has two different leftmost (rightmost) derivation, then the grammar It is diethyl-defined.

6. Analysis of sentence

If A => β, αβγ sentence is called beta] with respect to the rule A-> β direct phrase (also called simple phrases). A sentence directly to the right phrase referred to the handle of the sentence, the concept of the right handle only suitable sentence. For unambiguous grammar, sentence of a unique handle is the right of all its direct phrase that left most of the sentence is both leftmost his phrases directly handle.

 

Second, try to write grammar PL / 0 language. (Or do you think the better language rules) <Program> → <Block>.

<Block> → [<Constant Description section>] [<Variable Description section>] [<Process Description section>] <statement>

<Constant Description section> → CONST <constant definitions> {, <constant definitions>};

<Constant defines> → <identifier> = <unsigned integer>

<Variable Description section> → VAR <identifier> {, <identifier>};

<Process Description section> → <Process header> <Block>; {<Process Description section>}

<Process header> → procedure <identifier>;

 <Statement> → <assignment> | <conditional statements> | <When the loop type> | <procedure call statement> | <statement read> | <write statements> | <compound statement> | <empty>

<Assignment statement> → <identifier>: = <expression>

<Conditional statement> → if <condition> the then <statement>

<Modified transport operator> → + | -

<Multiplication and division operator> → * | /

<Relational operators> → = | # | <| <= |> |> =

<Item> → <factor> {<multiplication and division operator> <factor>}

<Factor> → <identifier> | <unsigned integer> | (<expression>)

<Procedure call statement> → call <identifier>

<When the loop type> → while <condition> do <statement>

Guess you like

Origin www.cnblogs.com/zhff/p/11590114.html