Four grammar and language work summary and comb

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

We all know that a language certainly his grammar to describe, it's the complete definition includes both syntax and semantics. Language and syntax refers to a set of rules, which may be formed and used to generate an appropriate program. Currently widely used is context-free grammar, that is, with a context-free grammar describing as a tool of programming, such as using A: = B + C represents a legitimate assignment, then A: = B + is not a legal assignment statement.

  What is grammar? Equivalent semantic analysis grammar linguistics (human language), that is the meaning of a sentence analysis indicated. It is generated according to the intermediate code or object code.

Is represented by EBNF (EBNF form is called a ABNF description): <Sentence> :: =  <Subject> <predicate>

                               <Subject> :: =  <pronouns> <noun>

                               <Pronouns > :: = me | you | him

                               <Noun > :: = Wang | Students | worker | English

                               <Predicate > :: =  <verb> <direct object>

                               <Verb > :: = Yes | learning

                               <Direct object > :: = <pronouns> | <noun>

(1) formal grammar definition:

  •  G=(VT , VN , P , S)
  •  V T : a set of terminators, terminator is the symbolic language defined by the grammar, sometimes referred to as a token.
  •     V N : the set of non-terminal, non-terminal symbol is used to indicate the syntax component, sometimes referred to as "grammar variables", other grammatical elements can be introduced
  •     P: set of production
  •     S: start symbol

(2) a symbol string operations:

  •   Connected symbol string: εx = xε = x;
  •   The set of products: AB = {xy | x∈A, y∈B}; {ε} A = A {ε} = A;
  •   Symbol string exponentiation: x = abc, x ^ 2 = abcabc;
  •   Exponentiation collection

Positive closure with closure A + A *: A * = {ε} ∪A +

(3) Grammar Category:

      

 

 

(4) operation definition language

 Language: determining a set at a particular symbol string in the alphabet. Empty set ε, {ε} is the set of fit this definition language.

 Language calculation example:

  •   L∪D full set of letters and numbers
  •   The set of all strings of symbols consists of a letter followed by a LD digits
  •    L4 all symbols of four-letter string set
  •   L * a set of letter strings of all symbols (including ) of
  •   The set of all strings of symbols L (L∪D) * begin with a letter followed by letters, digits
  •   The set of all D + symbol string by one or several digits

(5) sentence, sentences and language:

  •   Sentence: S = *> x, x∈ (Vn∪Vt) *, where S = *> x generalized derivation.
  •   Sentence: S = *> x, x∈Vt *, where S = *> x is a generalized derivation, x must terminator closure (may ε).
  •   Language: L (G [S]) = {x | S = +> x and x is Vt *}, where S = +> x is derived using at least one rule.

(6) syntax tree seeking phrases, simple phrases and handles:

  •   The phrase: symbol string end node subtree formed.
  •   Simple subtree: Only one sub-tree branch.
  •   Simple symbol string end node subtree formed: Direct phrases (phrase simple).
  •   Handle: subtree leftmost leaf nodes of the tree only when all the sub-tree of two generations of father and son lined up from left to right, it is the sentence of the handle.

Ambiguity (7) Semantics

  If the grammar G in the presence of a sentence is not only a syntax tree, called the sentence is ambiguous. If the grammar contains ambiguous sentences, claimed that the grammar is ambiguous.

2. Try to write grammar PL / 0 language. (Or do you think the better language rules)

Integer n

  n->1|2|3|...|9|n

I identifier

  i->a|b|c|……|y|z|A|B|C|……|Y|Z1|2|3|...|9|_

Expression e

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

Conditional statement :: = if <condition> then <statement>

Assignment :: = <id>: = <expression>

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

= Function :: = <main function>

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

Guess you like

Origin www.cnblogs.com/ldtasdf/p/11599820.html