Job four:

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

This chapter learned grammar and knowledge of the language, such as: formal definition of the concept of visual grammar, symbols and strings, grammar and language, the type of grammar, syntax tree and sentence analysis.

The alphabet is a nonempty finite set of elements, the elements called symbols, also called alphabet symbol set.

Any finite sequence of symbols from the alphabet is called a string.

Grammar G = (Vn, Vt, P, S), wherein the non-terminator Vn set; Vt of the terminator is set; P is the set of productions, comprising at least one non-terminal symbol; S or an identifier for the start symbol.

When n = 0, the Aⁿ, Aⁿ empty string ε.

Derivation method is divided into a leftmost derivation, rightmost derivation (derivation specification). -> represents production, => represents a formula derived.

Grammar is divided into Type 0, Type 1, Type 2 and Type 3.

Type 0 Grammar: α-> β, both are set, and containing at least one non-terminal symbol.

Type 1 grammars (context-sensitive grammar): Each α-> β are satisfied |β|≥|α|.

Type 2 grammar (grammar context can not be): Each α-> β are satisfied α is a nonterminal symbol.

Type 3 grammar (regular grammar): A-> aB or A-> a.

Grammar fragment conditional statement: <conditional statements> -> if <condition> then <statement> | if <condition> then <statement> else <statement>

The syntax tree leaves called derivation. If there is a grammar two different syntax tree, it says that the grammar is ambiguous.

Sentence into phrases and phrases directly handle.

The phrase is the final result of the combination of each syntax tree, a direct result of the final phrase syntax tree is only a tributary of the left handle is the most direct phrases.

 

2. Try to write grammar PL / 0 language.

Integer n n -> ... | 0 | 1 | 2 | 3 | ...

Identifier i i -> <Identifier>

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

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

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

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

function    

type_specifier to

VOID

| CHAR

| INT

| FLOAT

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

...

 

Guess you like

Origin www.cnblogs.com/tao614/p/11577411.html