Grammar and syntax summary and comb

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

Chapter: formal grammar definition of context-free grammar, regular grammar derivation, form phrases, tree analysis, finite automaton ambiguity definition automaton, grammar, and determines expression minimize DFA Equivalence of NFA .

Grammar is understood that: a grammar definition language description of the structure, i.e., from the form and the predetermined description language structure, called grammar

And it has its grammatical rules: by establishing a set of rules (production), to describe the grammatical structure of the sentence.

Listen to the teacher in the classroom, it is more familiar grammar quad, derivation, sentences, phrases and the like.

In the exercises, derivation is more familiar, to give a specific sentence, to get out of this sentence by deduction, but if we simply read a book on this concept and description, will be very abstract, because the definition of many things, but I see a mess, or by the teacher tells the class exercises and exercises to understand.

But so far, I was not very clear syntax context. Meanwhile in derivation, special attention is the rightmost derivation also called canonical derivation, but most left only one definition is the most left. After making the syntax tree, sentences, phrases, direct phrases, the syntax tree requires canonical derivation (rightmost derivation), to understand what the phrase is, what is the handle directly with the phrase, you can directly see the answer in the syntax tree Come.

In grammar ambiguity in, or are not familiar with, but after the Internet to find disambiguation grammar exercises related to its interpretation, he understood how the derivation of this exercise.

In the language construct grammar, grammar or structure for the unskilled.

In general, the second chapter is not complicated, as long as you understand, it is easy to do, but part of the knowledge of the content is easy to generalize too abstract, a bunch of strings of symbols with description letters strings do not understand.

2、

Try to write PL / 0 language grammar.

Integer n

I identifier

Expression e

Conditional statements

Assignment

Compound statement

function

program

...

 

Reference to http://www.doc88.com/p-9713794071234.html

Since no, they search the Internet

 <Program> -> <Block>

<Block> -> [<Constant Description section>] [<Variable Description section>] [<Process Description section>] <statement>

<Constant Description Part> -> CONST <constant definitions> {, <constant definitions>};

<Constant defines> -> <identifier> = <unsigned integer>

<Unsigned integer> -> <number> {<number>}

<Variable Description section> -> VAR <identifier> {{identifier}};

<Identifier> -> <letter> {<letters> | <number>}

<Process Description section> -> <Process header> <points extent>; {<Process Description section>}

<Process header> -> procedure <identifier>;

<Statement> -> <assignment> | <conditional statements> | <When the loop type> | <procedure call statement> | <statement read> | <Write statement> | <compound statement> | <empty>

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

<Compound statement> -> begin <statement> {: <statement>} <end>

<Condition> -> <expression> <relational operator> <expression> | OOD <expression>

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

<Item> -> <Factor> {<multiplication and division operator> <factor>}

<Factor> -> <identifier> | <unsigned integer> | (<expression>)

<Modified transport operator> -> + | -

<Multiplication and division operator> -> * | /

<Relational operator> -> = | # | <| <= |> |> =

<Conditional statements> -> if <condition> then <statement>

<Procedure call statement> -> call <identifier>

<When the loop type> -> while <condition> do <statement>

<Read statement> -> read (<identifier> {, <Identifier>})

<Write statement> -> write (<identifier> {, <Identifier>})

<Letter> -> a | b | c .... x | y | z

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

Guess you like

Origin www.cnblogs.com/jinwhy/p/11577424.html