1/13

# xt07答案.doc

0/100

xt07答案.doc

a)

b) 后缀式: a b c + uminus *
c) 三地址代码序列为:

t1:= b + c
t2 := - t1
t3 := a* t2

a):四元式序列为:

op
arg1
arg2
result
(1)
+
a
b
t1
(2)
+
c

t2
(3)
*
t1
t2
t3
(4)
uminus
t3

t4
(5)
+
a
b
t5
(6)
+
t5
c
t6
(7)
+
t4
t6
t7

b):三元式序列为:

op
arg1
arg2
(1)
+
a
b
(2)
+
c
d
(3)
*
(1)
(2)
(4)
uminus
(3)

(5)
+
a
b
(6)
+
(5)
c
(7)
+
(4)
(6)

c):间接三元式表示:

statement

op
arg1
arg2
(1)
(11)
(11)
+
a
b
(2)
(12)
(12)
+
c
d
(3)
(13)
(13)
*
(11)
(12)
(4)
(14)
(14)
uminus
13

(5)
(11)
(15)
+
(11)
c
(6)
(15)
(16)
+
(14)
(15)
(7)
(16)

a)
b) 后缀式为: i 10 <=  a i [] 0 = while
从理论上可以说 while ( i <= 10 ) a[i] = 0; 的后缀式如上面表示。但若这样表示,在执行while操作时,赋值语句已经执行,这显然与语义不符,因此改为:
i 10 <= <下一个语句开始地址> BM a i [] 0 = <本语句始址>BRL

c) 三地址代码序列为:

100   if i <= 10 goto 102
101   goto 106
102   t1 := 4 * i
103   t2 := a
104   t2[t1] := 0
105   goto 100
106

首先消除图7.14中翻译模式的左递归:
(注:'{','}'为元语言符号。)
递归预测翻译程序如下:
TYPE
PROCEDURE E ;
VAR
BEGIN
{ E.truelist, E,falselist } := T;
WHILE ( lookahead == 'or ' ) DO
BEGIN
match(or);
{ T.truelist, T.falselist } := T;
E.truelist := merge(E.truelist, T.truelist);
E.falselsit := T.falselist
END;
return({E.truelist, E.falselist})
END;
PROCEDURE T;
VAR