1. carding second chapter, understand and write a summary.
String of symbols : symbols and poor sequence called a string. Arbitrary symbol alphabet symbol string consisting of the sequence is. What sign symbol does not contain an empty string called string of symbols to represent the Greek letter ε.
Sentence : containing only terminal symbols of the grammar of a sentence is a sentence.
Grammar : grammar is to define a set of formal rules describing the grammatical structure of the language,
The object of the grammar is to use a programming language grammar rules to an appropriate number of pieces of all components describe the programming language,
Divided into 0-type grammar (phrase grammar), type 1 grammars (context-sensitive grammar), type 2 grammars (context-free grammar | left linear grammar), type 3 grammar (right-linear grammar | formal grammar)
The relationship between the four grammar:
Language : the set of all sentences of grammar is the grammar corresponding language.
Syntax Tree : in a natural language, the analysis may be visually represented by a tree structure of the sentence; in the form of language, the sentence structure is analyzed by the grammar syntax tree visually.
Provided grammar G [S] = (V n- , V T , P, S), for any grammar G [E] of a sentence exists a corresponding syntax tree.
The phrase : a sentence in the syntax tree consisting of any sub-symbol sequence are leaf nodes of the phrase sentence.
Direct phrases : phrases include direct phrases, phrases can be determined directly.
Recursion : recursive rules: nonterminals same rule in the rule of the left and right portions
Recursive grammar: for any of a grammar nonterminals, if such a right to establish a derivation of the portion nonterminal again, the grammar is recursive. Such as: U-> Vx, V-> Uy | z,
Although these two rules are not recursive rules, but the grammar is composed of recursive grammar U-> Vx-> Uyx. It contains a recursive grammar rule must be recursive grammar, but not necessarily contain recursive recursive grammar rules.
Leftmost derivation : if a => b, and in each "step derivation", the leftmost are replaced by a nonterminal, such derivation is called leftmost derivation.
E => E+T => T+T => F+T => i+T => i+F => i+i
Rightmost derivation : if a B, and in each "step derivation", the rightmost are replaced in a nonterminal, such derived as claimed rightmost derivation, also called canonical derivation.
E => E+T => E+F => E+i => T+i => F+i => i+i
Ambiguity : a grammar of a sentence if there is more than one parse tree, then the sentence is ambiguous sentences, grammar contains ambiguous sentence is ambiguous grammar.
2. 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>
<Unsigned integer> → <number> {<number>}
<Variable Description section> → VAR <identifier> {, <identifier>};
<Identifier> → <letter> {<letters> | <number>}
<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>
<Compound statement> → begin <statement> {; <statement>} end
<Condition> → <expression> <relational operator> <expression> | ODD <expression>
<Expression> → [+ | -] <item> {<subtraction operator> <term>}
<Item> → <factor> {<multiplication and division operator> <factor>}
<Factor> → <identifier> | <unsigned integer> | (<expression>)
<Modified transport operator> → + | -
<Multiplication and division operator> → * | /
<Relational operators> → = | # | <| <= |> |> =
<Conditional statement> → if <condition> the then <statement>
<Procedure call statement> → call <identifier>
<When the loop type> → while <condition> do <statement>
<Read statement> → read (<identifier> {, <Identifier>})
<Write statement> → write (<expression> {, <expression>})
<Letter> → a | b | c ... x | y | z
<Number> → 0 | 1 | 2 ... 7 | 8 | 9