【发布时间】:2018-12-14 12:25:38
【问题描述】:
在三个地址代码中,一个分支只能有一个二元关系运算符,
例如
if x relop y goto L1, where relop is (!=,==,>,>=,<,<=)
以下如何表示为三地址码格式:
j = 0
while(j < 10 || j < 20)
{
System.out.println(i);
j++;
}
这是我的解决方案,显然是不正确的:
main:
j = 1
sum = 0
L2:
if j < 10 || j < 20 goto L3
goto L4
L3:
mt2 = sum + 1
sum = mt2
mt3 = j + 1
j = mt3
goto L2
L4:
sum = 2
【问题讨论】:
-
你需要在if指令前将
j < 10 || j < 20分解成三个地址码,然后在里面测试结果是否为假。 -
感谢您的回复!例如,你不能有这个,
mt1 = j < 10因为x op y其中 op 只能是(+,-,\,*,&&, or ||)@Johan -
@webchatowner 然后你可以使用
jlt10 = true; if j < 10 goto L1; jlt10 = false; L1:之类的东西来实现jlt10 = j < 10。
标签: parsing compiler-construction tacit-programming