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.val ,T.val,E.val)
E→E-T {E.place:=newtemp; emit(E.place , ":=" , E.place'-' , T.place)} (-, E.val ,T.val,E.val)
E→T {E.place:=T.place;}
T→T* F {T.place:=newtemp; emit(T.place , ":=" , T.place'*' , F.place)} (*, T.val ,F.val,T.val)
T→T/F {T.place:=newtemp; emit(T.place , ":=" , T.place'/' , F.place)} (/, T.val ,F.val,T.val)
T→F {T.place:=F1.place;}
F→P^ F {T.place:=newtemp; emit(F.place , ":=" , P.place'^' , F.place)} (^, P.val ,F.val,F.val)
F→P {F.place:=newtemp; emit(F.place , ":=" , P.place)}
P→(E) {P.place:=E.place}
P→i {p:=lookup(id.name); if p<>nil then P.place:=i else error}