1.语法文法G[E]如下所示:
–E→E+T | E-T | T
–T→T* F | T/F | F
–F→P^ F | P
–P→(E) | i
- 要求构造出符合语义分析要求的属性文法描述
解:
E-->E+T { E.place:=newtemp; emit(E.place,':=',E.place '+' , T.place) }
E→E-T { E.place:=newtemp; emit(E.place,':=',E.place '-' , T.place) }
E→T { E.place:=newtemp; emit(E.place,':=', T.place) }
T→T* F { T.place:=newtemp; emit(T.place,':=',T.place ' * ' , F.place) }
T→T/F { T.place:=newtemp; emit(T.place,':=',T.place ' / ' , F.place) }
T→F { T.place:=newtemp; emit(T.place,':=' , F.place) }
F→P^ F {F.place:=newtemp; emit(F.place, ' := ' , P.place, ' ^ ' , F.place)}
F→P { F.place := newtemp;emit(F.place, ' := ', P.place) }
P→(E) { P.place := E.place; }
P→i { P.place := i }