2 Understanding grammar and language work

1. understood that symbol string and set operations.

L={A,B, … ,Z,a,b, … ,z}

D={0,1, … ,9}

Description meaning under represented:

LUD: full set of letters and numbers

The LD : All symbol string consisting of a letter followed by a set of digits

L . 4 : the set of all strings of symbols consisting of four letters

* L : all the symbols of the alphabet string includes a null symbol strings set

+ D : all symbols beginning with the letter strings, followed by the letter, digits collection

L (an LUD) * : all the symbols of one or several sets of strings of digits

 

2. grammar G (Z): Z-> aZb | ab definition of what kind of language?

Z->ab

Z->aZb->aabb

Z->aZb->aaZbb->aaabbb

A plurality of a plurality of b followed by all the group consisting of a symbol string, and the number a is equal to the number of b.

 

 

3. Write materials grammatical forms quad page identifiers 2.2 22 cases (VN, VT, P, S ).

Set I of identifier, L lowercase, D digital

VN={I,L,D}

VT={L,D}

P={I->L,I->IL,I->ID,L->L,D->D}

S={I}

 

4. Write the following expressions leftmost derivation, rightmost derivation.

G (E):

E=> E + T | T

T=>T * F | F

F=>(E)| i

i*i+i

i+i*i

i+(i+i)

 Observe different leftmost and rightmost derivation process.

i * i + i leftmost推导:

E=>E+T=>E+T+T=>T+T+T=>T*F+T=>F*F+T=>i*F+T=>i*i+T=>i*i+F=>i*i+i

i * i + i rightmost derivation:

E=>E+T=>E+F=>E+i=>T+i=>T*F+i=>T*i+i=>F*i+i=>i*i+i

i + i * i leftmost推导:

E=>E+T=>T+T=>F+T=>i+T=>i+T*F=>i+F*F=>i+i*F=>i+i*i

i + i * i most Right derivation:

E=>E+T=>E+T*F=>E+T*i=>E+F*i=>E+i*i=>T+i*i=>F+i*i=>i+i*i

i + (i + i) leftmost推导:

E=>E+T=>T+T=>F+T=>i+T=>i+F=>i+(E)=>i+(E+T)=>i+(T+T)=>i+(F+T)=>i+(i+T)=>i+(i+F)=>i+(i+i)

i + (i + i) most Right derivation:

E=>E+T=>E+F=>E+(E)=>E+(E+T)=>E+(E+F)=>E+(E+i)=>E+(T+i)=>E+(F+i)=>E+(i+i)=>T+(i+i)=>F+(i+i)=>i+(i+i)

 

Guess you like

Origin www.cnblogs.com/seele233/p/11505691.html