4. Summary and combing grammar and language

1. carding second chapter, understand and write a summary.

 

We learn strings of symbols, sentences, syntax tree, phrases, direct phrases, grammar, most left, rightmost derivation, language, ambiguity.

Knowledge string of symbols

(1) alphabet. Nonempty finite set of symbols. Typical symbols are letters, numbers, punctuation and various other operators.

(2) the symbol string. Alphabet defined on a finite sequence of symbols of the alphabet of symbols.

Symbol string set exponentiation: A0 = εA0 = ε, A1 = AA1 = A, A2 = AAA2 = AA, ...

Symbol string closure set operation. Positive closure: A + = A1∪A2∪A3∪ ... A + = A1∪A2∪A3∪ .... Closure: A * = A0∪A + A * = A0∪A +.

sentence

 Sentence contains only terminal symbols of the grammar of a sentence. Syntax tree terminator sequence from left to right, the sentence is a special case. Z = +> x. For grammar G = (VT, VN, S, φ), if, α is called a current sentence grammar.

Syntax tree

The syntax tree is a graphical representation of sentence structure, it represents the derivation result of the sentence, useful in understanding the grammatical structure of the sentence level. Simply put, the syntax tree is the tree deriving were formed in accordance with a rule. Characteristics analysis tree: each node are marked. Root labeled by the start symbol of grammar; each internal node labeled by a nonterminal, its right portion of each child node of the symbol generator derivation of this formula nonterminal used sequentially labeled from left to right; a leaf node or terminal nonterminal symbol mark, which lined up from left to right, the sentence constituted.

The phrase, direct phrases, handle

grammar

Grammar is the definition and description of the structure of the language. And it was used in a predetermined description language from formal structures referred to as "grammar" (or "grammar").

Grammar definition quad: G = (Vn, Vt, P, Z) G = (Vn, Vt, P, Z). VnVn non-terminal symbols set, VtVt set of terminal symbols, both collectively vocabulary table (V); P is of formula (rules) set; Z is the start symbol (identification code).

Leftmost derivation: if a => b, and in each "step derivation", the leftmost are replaced by a nonterminal, such derivation is called leftmost derivation.

Rightmost derivation: also known as canonical derivation, if a => b, and in each "step derivation" in both replace a rightmost nonterminal, called this derivation is rightmost derivation.

Ambiguous grammar

The presence of two different syntax tree of a sentence grammar defined.

Ambiguity problem is undecidable.

In the presence of a sentence grammar, it has two different specifications (rightmost) derivation.

There is a sentence grammar, it has two different specifications (far left) of the Statute, that certain norms sentence handle is not unique in the statute.

Such as: L (G) = L (G ') represents the grammar is equivalent to, but does not mean that language equivalents; more than one language a language. L represents language, G represents a grammar

Disambiguation 

Most recent Last matching principle

 

2. Try to write grammar PL / 0 language.

Integer n   

  n ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

 

I identifier 

  I :: = <letters> | i <letters> | i <number> 

<Letters> :: =  A | B | C | D | E |  ... | W | X | Y | Z

<Number> :: = 0 |. 1 | 2 |. 3 |. 4 |  . 5 |. 6 |. 7 |. 8 |. 9

 

Expression e 

 e :: = [+ | -] <item> {<+> <term>}

 e ::=[+ | -] x { + x }

<Item> :: = <factor> {<*> <factor>}

<项> x ::= y  { * y}

<Factor> :: = <identifier> | <unsigned integer> | '(' <expression> ')'

<Factor> y :: = i | n | (e)

 

Conditional statements

<Conditional statement> :: = IF <condition> THEN <statement>

<Conditional statement> :: = if A then B

 

Assignment

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

Compound statement

<Compound statement> :: = BEGIN <statement> {; <statement>} END

<Statement> :: = <assignment statement> | <conditional statements> | <When the loop type> | <procedure call statement> | <statement read> | <Write statement> | <compound statement> | <empty>

 

function

 

program

<Program> :: = <Block>.

<Block> :: = [<Constant Description section>] [<Variable Description section>] [<Process Description section>] <statement>

<Constant Description part> :: = CONST <constant definitions> {, <constant definitions>};

<Constant defines> :: = i = n

<Variable Description part> :: = VAR i {, i};

<Process Description section> :: = <process header> <Block> {; <Process Description section>};

<Process header> :: = PROCEDURE i;

 

Guess you like

Origin www.cnblogs.com/a131452/p/11583680.html