1702 fourth job (grammar and language summary and sort)

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

  1. What is grammar? The second chapter of history has been gradually exposing, come look at this issue, I feel like an innocent teenager into a young Mongolian children from ignorance, then what is the grammar of it?

  Grammar is a definition and description of the structure of language, from formal description language structure and rules, also known as syntax. Any grammar can be represented as a four-tuple = G (V T , V N , S, [Phi]) V T is a nonempty finite set, each of its elements are called terminal symbols. V N is a nonempty finite set, each of its elements is called nonterminal. V T ∩V N = [Phi] S is a special nonterminal, called the start symbol of the grammar. φ is a nonempty finite set, each of its elements is called production.

  2. Language: determining a particular set of symbols in sequence on the alphabet.

  3: Grammar writing conventions:

  End of lowercase alphabetic characters of the order front,

  Such as: a, b, c calculation symbols such as: +, -, *, /

  Punctuation marks, such as: the parentheses, commas, colons, numbers equal numbers 1, 2, ..., 9

  Blackbody string, such as: id, begin, if, then

  Nonterminal symbol ordering front of uppercase letters, such as: A, B, C

  Start symbol S capital letter writing method used italic lowercase string of symbols, such as: expr, term, factor, stmt

  Capital letters rearward grammar symbol sequence, such as: X, Y, Z

  End symbol sequence by the order of the lower case letters, such as: u, v, ..., z

  Grammar symbol string lowercase Greek letters, such as: α, β, γ, δ

  Can be used directly instead of generating the set of quadruple type described grammar, a production of the first symbol is a left portion of the start symbol of grammar.

  4. phrase, and the phrase directly handle: for grammar = G (V T , V N , S, [Phi]), a sentence is assumed αβδ grammar G, if there is

= S * > αAβ, and = A + > beta], is called beta] sentence αβδ nonterminal A on the phrase . If there is: S = * > αAβ, and A => β

Called β is a phrase sentence αβδ directly on nonterminal A of. A sentence of direct leftmost phrase called the handle of the sentence.

  Parse tree: a graphical representation of derivation, also known as the derivation tree. It ordered a directed tree, and therefore has a property tree; analyze tree features: 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.

  Subtree: a unique parse tree node, along with all its descendant nodes labeled edges connecting, these nodes and these nodes. Mark the root of sub-tree may not start symbol of the grammar. If the sub-root of the tree marked as non-terminal symbols A, which may be referred to as A- subtree subtree.

  Relationship subtree with the phrase: All leaf nodes in a subtree are arranged from left to right to form this phrase sentence with respect to the sub-tree root; all leaf nodes of the parse tree only father and son subtree lined up from left to right, this is formed directly phrase sentence with respect to the sub-tree root; parse tree, the leftmost leaf node of the tree only if all the sub-tree of the father and son lined up from left to right, which is sentence handle.

  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 grammar of ambiguity. Ambiguity problem is the absence of an algorithm is not determined, it can be determined accurately in a limited step whether a grammar is ambiguous. You can find some sufficient conditions (not necessarily a prerequisite), grammar when these conditions are met, you can be sure that the grammar is unambiguous.

  Eliminate ambiguous grammar: grammar mapping programming language IF statement: stmt if expr then stmt | if expr then stmt else stmt | other sentence if E1 then if E2 then S1 else S2 has two different parse tree. The use of "recently last matching principle": else the nearest must match that did not match then. It occurs between then and else statements must be "matched." The so-called matching statement is not mismatched statement? If-then-else statements, or any other non-conditional statements. Grammar rewritten: stmtmatched_stmt | unmatched_stmt matched_stmtif expr then matched_stmt else matched_stmt | other unmatched_stmt if expr then stmt | if expr then matched_stmt else unmatched_stmt

 

 

  

2. Try to write grammar PL / 0 language.

Integer n: provided grammar G (T): T-> NT

            N->0|1|2|3|...|9

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

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

Conditional statements: <conditional statement> :: = if <condition> the then <statement> [the else <statement>]

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

Compound statement: <compound statement> :: = begin <statement> {; <statement>} end

Function: <function definition> :: = <Description Type> <function name> <compound statement>

Program: <program> :: = <Block>.

 

 

Guess you like

Origin www.cnblogs.com/moxiaomo/p/11577476.html