The fourth work - grammar and language summary and comb

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

In the second chapter of the study, we learned the symbol, the symbol string, sentences, syntax tree, phrases, direct phrases, handles, grammar, most left, rightmost derivation, language, ambiguity.

1, symbols and strings

Alphabet: The alphabet is a nonempty finite set of elements, referred to as a symbol alphabet elements, also referred to as alphabet symbol set. Traditional symbol alphabet letters, numbers, punctuation and various other operators.

String of symbols: the symbol alphabet composed of any symbol string and poor sequence. The symbol string of the alphabet A = {a, b, c} alphabet by the composition comprising: {ab, ac, bc, abc, a, b, c}. If there is a symbol string of m symbols x, is called the length m, it is expressed as | x | = m. Allow null symbol strings, i.e., does not include any symbol string of symbols, represented by [epsilon], a length of 0, i.e. | ε | = 0.

Symbol string operation: ① connected symbol string: εx = xε = x;

       ② set of product: AB = {xy | x∈A, y∈B}; {ε} A = A {ε} = A;

       ③ symbol string exponentiation: x = abc, x ^ 2 = abcabc;

       ④ exponentiation set: x ^ 0 = e; x ^ 1 = x; .....; (Powers and elementary mathematical consistency)

       ⑤ A + positive closure with closure A *: A * = {ε} ∪A +

2, in the form of grammar and language definitions

Grammar: grammar is described in the form of so-called rules of the grammatical structure of the language. Any grammar can be represented as a four-tuple G = (, P, S). It is a nonempty finite set, each of its elements is called nonterminal; is a nonempty finite set, each of its elements is called terminal symbols; S is a special nonterminal, called grammar start symbol; P rule (α → β) is set.

3, the type of grammar

Type 0 grammar / unrestricted grammar: α-> β, where α∈ (Vn∪Vt) * and containing at least one non-terminator, β∈ (Vn∪Vt) *. Type 1 grammar / context-sensitive grammar: αAβ-> αuβ, wherein A∈Vn, α, β∈ (Vn∪Vt) *, u∈ (Vn∪Vt) +.

Type 2 grammar / context-free grammar: A-> β, where A∈Vn, β∈ (Vn∪Vt) *. Commonly used in syntactic analysis.

Type 3 grammar / regular grammar: lexical analysis commonly used in   

    . I Right Linear Grammar: Only the right push-expanded, A-> αB | α, A, B∈Vn, α∈Vt *.   

    . Ii left linear grammar: Only the left push-out deployment, A-> Bα | α, A, B∈Vn, α∈Vt *.

4, context-free grammar and syntax tree

For context-free grammar, the syntax tree is a geometric representation of the derivation of the sentence. When a given symbol string, attempts to follow the rules of a grammar or a symbol string configuration syntax tree for the derivation, it is thus recognized that a sentence grammar; symbol sequence when the termination of all the symbols, it is to identify It is not a grammatical sentence. Therefore, it was also called the syntax tree analysis parse tree or tree.

5, sentence analysis

Sentence structure analysis means is an algorithm for determining whether a given symbol string is a sentence grammar (or sentence). It is divided into two methods: ① top down analysis (rightmost derivation): derived from the start symbol sentences or sentence; ② bottom-up analysis (left-most reduction): reduction from the sentence or sentence start character.

6, phrases and handles

The phrase: S = *> αAδ and A = +> β, called beta] with respect nonterminal A sentence phrase αAδ; corresponding sub-tree concept in the syntax tree.

Direct phrases: where A => β is derived directly; subtree corresponding to the simple syntax tree. Each phrase is a direct right part of a rule.

Handle: phrases directly (i.e., a right portion of a rule), and having a leftmost of; simple subtree corresponding to the leftmost one.

Ambiguous grammar: if a sentence corresponding to a grammar exists two different syntax tree, comprising two or more of the rightmost (leftmost) derivation (statute), the grammar is ambiguous may be used; equivalence between grammar to eliminate ambiguity. It does not change any original syntax grammar rules, to increase the intake of non-form definition syntax, such as priority; a configuration equivalent unambiguous grammar.

Ambiguous ambiguous grammar and language: If two same language grammar generated, i.e., L (G) = L (G?), Both said to be equivalent grammar. Sometimes an ambiguous grammar can be converted into an equivalent, unambiguous grammar. Some languages, does not exist unambiguous grammar, this language is called the language of ambiguity.

In this chapter learning, mostly conceptual, look at the text would be more difficult to understand, but by example and do question can understand and master the learning content of this chapter.

2. try to write grammar PL / 0 language.

Integer n

       <Integer> :: = [-] <number> {<number>}

       <Number> :: = 0 | 1 | 2 | ... | 8 | 9

I identifier

 <Identifier i> :: = <letter> {<letters> | <number>}

<Letters> :: = a | b | ... | X | Y | Z

<Number> :: = 0 | 1 | 2 | ... | 8 | 9

Expression e

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

      <Addition operator> :: = + | -

      <Item> :: = <factor> {<multiplication operator> <factor>}

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

<Multiplication operator> :: = * | /

<Unsigned integer> :: = <number> {<number>}

<Identifier i> :: = <letter> {<letters> | <number>}

<Letters> :: = a | b | ... | X | Y | Z

<Number> :: = 0 | 1 | 2 | ... | 8 | 9

Conditional statements

       :: = if <condition> then <statement> :: = <expression> <relational operator> <expression> | ODD <expression>

Assignment

<Assignment statement> -> <identifier> = <expression>  

Compound statement

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

function

       <Function> :: = <Description Type> <function name> <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 statement>

program

       <Program> -> <external declarations> | <external declarations> <function>

<External declaration> -> <header> <function declaration> | <Other statements>

<Function> -> <return type> <identifier> <parameter> <compound statement>

 

Guess you like

Origin www.cnblogs.com/pangminhua/p/11598840.html