X:=(A+B) C, Y: DT(A+B) 间接代码 间接三元式 (1) op arg l arg2 (2) (1) a B (3) (2)* (3):=X(2) (4) (4)↑ D(1) (5) (5) Y(4)
X:=(A+B)*C;Y:=D↑(A+B); 间接 三元式 op arg1 arg2 (1) + A B (2) * (1) C (3) := X (2) (4) ↑ D (1) (5) := Y (4) 间接代码 (1) (2) (3) (1) (4) (5)
72说明语句 °为局部名字建立符号表条目 为它分配存储单元 符号表中包含名字的类型和分配给它的存储 单元的相对地址等信息
7.2 说 明 语 句 • 为局部名字建立符号表条目 • 为它分配存储单元 • 符号表中包含名字的类型和分配给它的存储 单元的相对地址等信息
72说明语句 721过程中的声明
7.2 说 明 语 句 7.2.1 过程中的声明
72说明语句 演示 Figure7.6 计算被声明名字的类型和相对地址 P→D {o∥set:=0} D→D:D D>id: T enter( id name, Ttype, offset) offset =offset T width T>integer T type: =integer; T width: =4) T→real i.type: =real; Twidth: =8) T→> array[ num of71 T type: =array(num. vaL, T1type); Twidth: =num,val x Twidth) T→个T1{Te:= pointer(T1pe); Twidth:=4}
7.2 说 明 语 句 演示Figure7.6 计算被声明名字的类型和相对地址 P → D {offset := 0} D → D ; D D → id : T {enter ( id.name, T.type, offset); offset := offset + T.width } T → integer {T.type := integer; T.width := 4 } T→ real {T.type := real; T.width := 8 } T→ array [ num ] of T1 {T.type := array (num.val, T1 .type); T.width := num.val T1 .width} T→ T1 {T.type := pointer (T1 .type); T.width := 4 }
72说明语句 722作用域信息的保存 所讨论语言的文法 P→DS D-D: Did TI proc id D; S 语义动作用到的函数 mktablelprevious) enter(table, name, type, offset) addwidth(table, width enterproc(table, name, newtable
7.2 说 明 语 句 7.2.2 作用域信息的保存 • 所讨论语言的文法 P → D S D → D ; D | id : T | proc id ; D ; S • 语义动作用到的函数 mktable(previous) enter(table, name, type, offset) addwidth(table, width) enterproc(table, name, newtable)