The fourth work - grammar and language summary and comb

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

First, the definition

  A sign language system, including syntax and semantics; main component is a grammar rule (production), we can generate the syntax tree is derived by a rule.

Second, the grammar G four-tuple (V N, V T , P, S)

  V N non-terminal symbol set

  V T is set terminator

  P rule (α → β) set

  S is the start symbol identifiers or at least to appear as the left portion in a rule.

Third, the type of grammar

Grammar discrimination tips

 

 Fourth, the syntax tree and ambiguity tree

  Syntax Tree: also known as parse tree for the sentence to derive contextual description.

 

  In the process of deriving α => β, it is necessary to follow the most left (right) derived, i.e., are on the leftmost (rightmost) of [alpha] nonterminal replaced. Rightmost derivation is also known as canonical derivation.

 

  If there is a grammar of a sentence corresponding to two different syntax tree, then the grammar is ambiguous in. And the ambiguous grammar undecidable.

 

  Note: ≠ grammar ambiguous language ambiguity

 

  → language is not ambiguous existence of a grammar is not ambiguous;

  Grammar is not ambiguous can not be determined →

 

Comprehension and Summary: grammar and language learning is the main rule of grammar transformation and generate a corresponding spanning accordance with the guidelines followed in its transformation process can be used to verify the uniqueness of the guidelines.


2. Try to write grammar PL / 0 language.

Integer n

Grammar: <n> :: = <integer>

I identifier

文法:<i>::=<id>

Expression e

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

<Item> :: = <factor> {<multiplication and division algorithms> <factor>}

<Subtraction operator> :: = + | -

Conditional statements

文法:<条件语句>::=if<条件>then<语句>

赋值语句

文法:<赋值语句>::=<id>:=<表达式>

复合语句

文法:<复合语句>::=begin<语句>{;<语句>} end

函数

文法:<函数>::=function <id>() :

        <上述各种组合>

程序

文法:<程序>::=<分程序>.

...

Guess you like

Origin www.cnblogs.com/lxml/p/11577477.html