directed acyclic graph(DAG) b*c+b*C 下
directed acyclic graph (DAG). b*c+b*c + * b c
7.3.2简单赋值语句的四元式)翻译 四元式形式:(op,arg1,arg2, result)或 result: =argl op arg2 语义属性:id.name,E. place 函数: lookup( id name); 过程: emit(t:= argl op arg2): newtemp; 产生式和语义描述 (1)s→id:=E RP: =lookup (id name); ifP≠ ni then emite(P“:=” E place) else error j
7.3.2 简单赋值语句的(四元式)翻译 四元式形式 : result := arg1 op arg2 语义属性: id.name, E.place 函数: lookup( id.name) ; 过程: emit(t := arg1 op arg2); newtemp; 产生式和语义描述: (1) S → id := E { P:=lookup (id.name) ; if P nil then emit( P “ :=” E.place) else error } (op ,arg1,arg2,result) 或
(2)E→>E1+E2 RE place:= newtemp emit( E place“:=”El. place“+”E2 place (3)E→>-E1 TEplace -newtemp, emit(E. place4:=“ minus” E place) (4)E→>(E1) fE place: =E. place) (5)E→id RE place: =newtemp; P:lookup(id name); if Ptnil then E place: =P else error)
(2) E→E1+E2 {E.place:= newtemp; emit(E.place“:=” E1 .place“+”E2 .place)} (3) E→ - E1 { E.place:=newtemp; emit(E.place“:=”“uminus” E1 .place)} (4) E→( E1 ) { E.place:= E1 .place} (5) E→id {E.place:=newtemp; P:=lookup(id.name); if Pnil then E.place:=P else error}
7.3.3简单说明句的翻译-翻译是指在符号表中登 录名字和性质。 最简单的说明句的语法: D→ integer( namelist〉|real( namelist 〈 namelist〉→( namelist〉,idid 用自下而上翻译文法改写: D→D1,jd I integer id I real id
7.3.3简单说明句的翻译-翻译是指在符号表中登 录名字和性质。 最简单的说明句的语法: D→integer〈namelist〉|real〈namelist〉 〈namelist〉→〈namelist〉,id|id 用自下而上翻译 文法改写: D→D1 ,id |integer id | real id
(1D-integer id enter(id, int); D att: =int (2)Real id tenter(id, real, D att: =reall (3DDI, d enter(id, D 1. att); D att: =D 1. att
(1)D→integer id{enter(id,int);D.att:=int} (2)D→real id{enter(id,real);D.att:=real} (3)D→D1 ,id{enter(id,D1.att); D.att:=D1.att}