Job two: understand the grammar and language

 

1. understood that symbol string and set operations

 

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

 

D={0,1, … ,9}

 

Description meaning under represented:

answer:

 

LUD: L set and set D of a set of all letters and digits

 

LD: set D letter by all symbols after the number with a set of L, e.g. A0, B1 ... composed of a set of strings, etc.

 

L4: the set of four-letter set L

 

L *: All letters of the symbol string while an empty string of symbols comprising a set of

 

D +: and all symbols beginning with the letter followed by letters, numbers consisting of a set of strings

 

All single or a plurality of sets symbol string of numbers: L (LUD) *

 

 

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

 

Answer: a Z-> aZb | ab available,
Z-> aZb-> aaZbb-> AAABBB

 

Thus: L (G) = {anbn | n> 1}

 

 

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

 

I->

 

L->

 

D->

 

answer:

 

I-> L | IL | ID

 

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

 

D-> 0|1|2|...|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)
to observe different leftmost and rightmost derivation process.

 

A: 1, i * i + i leftmost derivation:

 

E=>E+T=>T+T=>T*F+T=>F*F+T=>i*F+T=>i*i+T=>i*i+F=>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

 

  2, 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

 

Rightmost 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

 

  3, 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)

 

Rightmost 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/heiyedeshihouh/p/11511735.html