Compiler theory learning (5) grammar and language summary and comb

Carding second chapter, understand and write a summary.

grammar:

A set of tools to characterize the finite of infinite set. Rule will be explained with the structure of the sentence composition, described in language used to represent infinity sentence.

Sentence and sentence:

If the symbol string x is derived from the start symbol, grammar is called x G [S] sentence.

If x contains only terminator, x is called grammar G [S] sentence.

Language grammar describes all the grammar of the sentence collection.

Four kinds of grammar:

Type 0 grammar: α → β, wherein [alpha] comprises at least one non-terminal symbol.

Type 1 grammars (context-sensitive grammar): α → β, where | β | ≥ | α |, S → ε excluded.

Type 2 grammar (CFG): a → β, where a is a nonterminal symbol.

Type 3 grammar (grammar specification): A → a or A → aB.

Four kinds of grammar gradually increase the limit, it must be 0 grammar specification type grammar, the grammar type 1, type 2 grammar, context-free grammar grammar must be the type 0, type 1 ... grammar

Canonical derivation:

Rightmost derivation is derived specification, introduced by the specification derived sentence or sentence as the right specifications sentence.

Ambiguous grammar:

A sentence may correspond to a plurality of the syntax tree, a sentence may correspond to a plurality of the leftmost / rightmost derivation.

If a grammar of a sentence may correspond to two different syntax tree, called the grammar is ambiguous in.

Two different grammar may be the same language.

If all the grammar of a language is ambiguous, and claimed that this language inherent ambiguity.

Determine whether a grammar is ambiguous is recursively unsolvable.

 

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

Integer n

<Number> -> 0 | 1 | 2 ... | 8 | 9

I identifier

i::=1|2|3|..|a|b|c|d|...

Expression e

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

Conditional statements

if A then B

Assignment

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

Compound statement

 -> begin <statement> {; <statement>} <end> 

function

 

program

...

Guess you like

Origin www.cnblogs.com/xyqzzz/p/11600256.html