📄 7.4.4b.htm
字号:
<html>
<head>
<title>编译原理</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link type="text/css" rel="stylesheet" href="../css/specification.css">
</head>
<body>
<table align="right" width="300">
<tr>
<td><img src="../images/previous.gif" onmouseover="javascript:style.cursor='hand'"
onclick="vbscript:window.location.href='7.4.4.htm'" ></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'"
onclick="vbscript:window.location.href='7.5.0.htm'" ></td>
</tr>
</table>
<p><br>
<br>
<table>
<tr>
<td> </td>
<td class="content">假定E形如E<sub>1</sub><b>or</b> E<sub>2</sub> 。若E<sub>1</sub>为真,则立即可知E为真,于是E<sub>1</sub>.true与E.true是相同的。若E<span class="down"><sub>1</sub></span>为假,则必须对E<span
class="down"><sub>2</sub></span>求值,因此我们置E<span class="down"><sub>1</sub></span>.false为E<span
class="down"><sub>2</sub></span>的代码的第一条指令的标号。而E<span
class="down"><sub>2</sub></span>的真、假出口可以分别与E的真、假出口相同。类似可考虑形如E<sub>1</sub> <b>and</b> E<span class="down"><sub>2</sub></span>的E的翻译。至于形如<b>not</b>
E<span class="down"><sub>1</sub></span>的布尔表达式E不必生成新的代码,只要把E<span
class="down"><sub>1</sub></span>的假、真出口作为E的真、假出口即可。表7.5是按此方式将布尔表达式译成三地址代码的语法制导定义。注意E的true和false属性都是继承属性。
<br>
<font class="example">例7.3</font> 考虑如下表达式: <br>
a<b or c<d and e<f。
<br>
假定整个表达式的真假出口已分别置为Ltrue和Lfalse,则由表7.5的定义将生成如下的代码:
<br>
if a
<b goto Ltrue <br>
goto
L1 <br>
Ll :if c<d goto L2 <br>
goto
Lfalse <br>
L2 :if e<f goto Ltrue <br>
goto
Lfalse <br>
自然,这里的代码是未优化的,有冗余的指令。 <br>
<font class="example">例7.4</font> 考虑如下语句: <br>
while a<b do <br>
if c<d then <br>
x:= y
+ z <br>
else <br>
x:=
y - z <br>
根据上述语法制导定义和赋值语句的翻译模式,将生成下列代码: <br>
L<sub>1</sub>: if a<b goto L<sub>2</sub> <br>
goto L<sub>next</sub>
<br>
L<sub>2</sub>: if c<d goto L<sub>3</sub> <br>
goto L<sub>4</sub>
<br>
L<sub>3</sub>: t<span class="down"><sub>1</sub></span>
:= y+z <br>
x:=t<span
class="down"><sub>1</sub></span> <br>
goto L<sub>1</sub>
<br>
L<sub>4</sub>: t<span class="down"><sub>2</sub></span>:=y-z
<br>
x:=t<span
class="down"><sub>2</sub></span> <br>
goto L<sub>1</sub>
<br>
L<sub>next</sub>: <br>
</td>
</tr>
</table>
<br>
<br>
<table align="right" width="300">
<tr>
<td><img src="../images/previous.gif" onmouseover="javascript:style.cursor='hand'"
onclick="vbscript:window.location.href='7.4.4.htm'" ></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'"
onclick="vbscript:window.location.href='7.5.0.htm'" ></td>
</tr>
</table>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -