📄 7.4.3.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.2b.htm'" width="24" height="24" ></td>
<td>
<img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'"
onclick="vbscript:window.location.href='7.4.3b.htm'" width="26" height="24" ></td>
</tr>
</table>
<p><br>
<br>
<font class="title2"><b>7.4.3 控制流语句</b></font> </p>
<table>
<tr>
<td> </td>
<td class="content">现在我们考虑在<b>if</b>-<b>then</b> ,<b>if</b>-<b>then</b>-<b>else</b>,<b>while</b>-<b>do</b>语句中的布尔表达式的翻译。文法如下:
<p> S→<b>if</b> E <b>then </b>S<span class="down"><sub>1</sub></span>
<br>
| <b>if</b>
E <b>then</b> S<span class="down">1</span> <b>else</b> S<span class="down"><sub>2</sub></span>
<br>
| <b>while</b>
E <b>do</b> S<span class="down"><sub>1</sub></span> <br>
其中E是需要翻译的布尔表达式。在翻译过程中,我们假定可以用符号标号来标识一条三地址语句,并且假定函数newlabel每次被调用后都返回一个新的符号标号。
<br>
对于一个布尔表达式E,我们引用两个标号:E.true 是E为真时控制流转向的标号,E.false是E为假时控制流转向的标号。由图7.13和表7.4可以知道翻译控制流语句S的语义规则允许控
制从S的代码S.code之内转移到紧接S.code之后的那一条三地址指令。但是,有时此条紧接S.code之后的指令是一条无条件转移指令,它转移到标号为L
的指令。通过使用继承属性S.next可以避免上述连续转移的情况发生,而从S.code之内直接转移到标号为L的指令。S.next
之值是一个标号,它附属于继S的代码之后将被执行的第一条三地址指令。
<br>
控制流语句的代码结构见图7.13,语法制导定义见表7.4。
</td>
</tr>
</table>
<center><img src="7_13.gif" > </center>
<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.2b.htm'" width="24" height="24" ></td>
<td>
<img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'"
onclick="vbscript:window.location.href='7.4.3b.htm'" width="26" height="24" ></td>
</tr>
</table>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -