📄 7.4.3c.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.3b.htm'" width="24" height="24" ></td>
<td>
<img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'"
onclick="vbscript:window.location.href='7.4.4.htm'" width="26" height="24" ></td>
</tr>
</table>
<p><br>
<br>
<table>
<tr>
<td> </td>
<td class="content">
<p>类似的,在翻译if-then-else语句S→<b>if</b> E <b>then</b> S<sub>1</sub> <b>else</b>
S<sub>2</sub> 时,布尔表达式E的代码中有这样的转移指令:若E为真则转移到S<sub>1</sub>
的第一条指令,若E为假则转移到S<sub>2</sub>的第一条指令。如图7.13(b)
所示。与if-then语句一样,继承属性S.next给出了紧接执行S的代码之后将被执行的三地址指令的标号。在S<sub>1</sub>的代码之后有一条明显的转移指令goto
S.next,但S<sub>2</sub>之后没有。 <br>
图7.13(c)是while-do语句S→<b>while</b> E <b>do</b> S<sub>1</sub>的代码结构。我们建立了一个新的标号S.begin,并用它来标识E的代码的第一条指令。另一个标号E.true
标识S<span class="down">1</span>的代码的第一条指令。在E的代码中有这样的转移指令:若E为真则转移到标号为E.true的语句,若E为假则转移到S.next。同前面一样,我们置E.false为S.next。在S<sub>1</sub>的代码之后我们放上指令goto
S.begin,用来控制转移到此布尔表达式的代码的开始位置。注意,我们置S<sub>1</sub>.next为标号S.
begin, 这样在S<sub>1</sub>.code之内的转出指令就能直接转移到S.begin。 <br>
我们将在7.5节更详细地讨论有关控制流语句的翻译。那里使用一种称为“回填”的方法经过一遍扫描而翻译生成这些语句的代码。
</td>
</tr>
</table>
<table>
<tr>
<td><font class="yanshi"> 观看演示 </font></td>
<td><font color="blue" onmouseover="javascript:style.cursor='hand'"
onclick="javascript:open('applets/test7_6/Page1.htm','_blank','menu=no,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,left=100,top=100,width=890,height=600')">控制流语句的翻译</font></td>
<td><img src="../images/yanshi.gif" width="36" height="35"></td>
</tr>
</table>
<p><br>
</p>
<table align="right" width="300">
<tr>
<td>
<img src="../images/previous.gif" onmouseover="javascript:style.cursor='hand'"
onclick="vbscript:window.location.href='7.4.3b.htm'" width="24" height="24" ></td>
<td>
<img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'"
onclick="vbscript:window.location.href='7.4.4.htm'" width="26" height="24" ></td>
</tr>
</table>
</body>
</html>
<html><script language="JavaScript">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -