📅  最后修改于: 2020-12-06 07:27:32             🧑  作者: Mango
在语法定向翻译中,赋值语句主要处理表达式。表达式的类型可以是实数,整数,数组和记录。
考虑语法
S → id := E
E → E1 + E2
E → E1 * E2
E → (E1)
E → id
以上语法的翻译方案如下:
Production rule | Semantic actions |
---|---|
S → id :=E | {p = look_up(id.name); If p ≠ nil then Emit (p = E.place) Else Error; } |
E → E1 + E2 | {E.place = newtemp(); Emit (E.place = E1.place ‘+’ E2.place) } |
E → E1 * E2 | {E.place = newtemp(); Emit (E.place = E1.place ‘*’ E2.place) } |
E → (E1) | {E.place = E1.place} |
E → id | {p = look_up(id.name); If p ≠ nil then Emit (p = E.place) Else Error; } |