The second understanding of grammar and language work

1. understood that symbol string and set operations
LUD: a set composed of L and D, {A, B ... the Z, A, B, .. Z, 0,1, ...,}. 9
the LD: x belonging to the y L and D form a set of all strings belong, {A0, A1, ... B0, Bl, ..., A0, A1, ...} z9
L4: L set which belongs to the connection element consisting of four random set, {AAAA, BBBB, ... AAAB, ...}
L *: L set on the collection of all the finite elements long strings, {ε, a, B, ..., Z, a, b, ..., z, AA, ... ZZ, aa, bb, ..., zz, ab, aab ...}
all have poor long strings except ε, D consisting of the collection element: D + set, {A, B, ..., the Z, A, B, ..., Z, AA, ZZ ..., AA, BB, ..., ZZ, ab &, ...} AAB
L (an LUD ) *: m belongs to a set of L, n belonging to a set of basic L and D form of the set of all strings of finite length on this collection of elements, m, n, all the components of the set of strings

2. grammar G (Z): Z-> aZb | ab definition of what kind of language?
Production: Z-> aZb, Z-> ab "Z => ab, Z => aZb => a²b²

Reuse production: Z-> aZb, to obtain Z => aZb => a²Zb² ... => aⁿ-¹Zbⁿ-¹ => aⁿbⁿ

Therefore language L (G [Z]) = {aⁿbⁿ | n≥1}

3. Write grammar quaternion form materials 22 pages in Example 2.2 identifier (VN, NT, P, S).

I->I | IL |ID

L->a|b|c|...|x|y|z

D->0|1|...|8|9

 

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)

Leftmost derivation:

  • i*i+i :E=>E+T=>T+T=>T*F+T=>F*F+T=>i*F+T=>i*i+T=>i*i+i
  • i+i*i:E=>E+T=>T+T=>F+T=>i+T=>i+T*F=>i+F*F=>i+i*F=>i+i*i
  • i+(i+i):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)

Rightmost derivation:

  • i*i+i :E=>E+T=>E+=>E+ i =>   T + i =>  T * F  + i =>  T * i  + i =>  F * i  + i => i * i  + i 
  • i+i*i :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) :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/fqy1028/p/11511042.html