1. grammar G (Z): Z-> aZb | ab definition of what kind of language?
2. Write grammar quaternion form materials 22 pages identifiers in example 2.2.
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、G(Z):Z->aZb|ab
Z->aZb->aaZbb->aaaZbbb->aaaabbbb
That grammar G (Z) describes the G ( the Z ) = A n-** ** Nb
2、G=(VN,VT,P,S)VN={E、T、F} VT={a-z,0-9} P={E->T|ET|EF T->a-z F->0-9} S=E
3、①i*i+i的最左推导:E->E+T->T+T->T*F+T->F*F+T->i*F+T->i*i+T->i*i+F->i*i+i
最右推导:E->E+T->E+F->E+i->T+i->T*F+i->T*i+i->F*i+i->i*i+i
Syntax tree:
②i+i*i的最左推导:E->E+T->T+T->F+T->i+T->i+F*T->i+i*T->i+i*F->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
Syntax tree:
③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)
最右推导: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)
Syntax tree: