1. grammar G (Z): Z-> aZb | ab definition of what kind of language?
Z->aZb或Z->ab
The aZb -> aaZbb or aZb -> aabb
~~~~~~~~~~~~~~~~
Available so ....... A n- B n-
Therefore, G (Z): Z-> aZb | ab definition language is: L (G (the Z)) = {A n- B n- | n-> =. 1}
2. Write grammar quaternion form materials 22 pages identifiers in example 2.2.
Grammar quad form:
Grammar = G (V N , V T , P, S)
V n- = {W is (identifier), Q (letters), K (number)}
Vt={a,b,c,d...........z,0,1.......9}
P={W-->Q | K }
S={W}
3. Write the following expressions leftmost derivation and rightmost derivation syntax tree.
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, as well as the similarities and differences of the syntax tree.
(1) the most left:
E=>E+T=>E+F=>E+i=>T+i=>T*F+i=>T*i+i=>F*i+i=>i*i+i
Rightmost derivation
E=>E+T=>T+T=>T*F+T=>F*F+T=>i*F+T=>i*i+T=>i*i+F=>i*i+i
Derivation Tree:
(2)
Leftmost derivation:
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
Derivation Tree:
(3)
Leftmost derivation:
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+(T+i)=>E+(i+i)=>T+(i+i)=>F+(i+i)=>i+(i+i)
Derivation Tree: