2 compiler theory 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: a collection of all the letters and numbers

LD: by the following set of strings of letters with numbers

L4: a set of strings of symbols of the four-letter

L *: symbol string set by all of the letters

D +: all symbols of one or several strings of digits set

L (LUD) *: it is in line with a set of strings beginning with the letter, followed by letters, digits

 

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

A: too meaning of the questions:

1、Z->aZb

2、Z->aZb,得 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, VT, P, S).

A: I-> L | TL | TD

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

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

 S=

  

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.

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/cnw834575008/p/11511169.html