📄 7.6.2c.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.6.2b.htm'" ></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='7.6.2_2.htm'"></img></td>
</tr>
</table>
<br><br>
<table><tr><td>    </td>
<td class="content">
<p>考虑产生式(1) <p> S→if E
then M<SPAN class=down><sub>1</sub></SPAN> S<SPAN class=down><sub>1</sub></SPAN> N else M<SPAN
class=down><sub>2</sub></SPAN> S<SPAN class=down><sub>2</sub><br>
</SPAN>及其相应语义动作。其中标记非终结符号M和N标示出了编译中的重要位置。我们同样需要在S1的代码之后增加一条转移指令以跳过s<SPAN class=down><sub>2</sub></SPAN>的代码。我们采用标记非终结符号N来生成这条转移指令,见产生式(2)。N具有属性N.nextlist,这个指针指向一个表,此表包含由此N的语义规则所生成的转移语句(goto-)的四元式编号。现在让我们继续考虑产生式(1)的语义动作。需要回填表E.truelist中相应的转移指令的目标标号为M<SPAN
class=down><sub>1</sub></SPAN>.quad,即S<SPAN
class=down><sub>1</sub></SPAN>的代码的开始位置;并且回填表E.falselist中相应的转移指令的目标标号为M<SPAN
class=down>2</SPAN>.quad,即S2的代码的开始位置。表S.nextlist中相应的指令包括跳出S<SPAN
class=down><sub>1</sub></SPAN>,S<SPAN
class=down><sub>2</sub></SPAN>的转移指令和N生成的转移指令。 <p>
让我们考虑产生式(8)的语义动作。按执行顺序而言,在L<SPAN class=down>1</SPAN>之后的语句应是S的开始。于是,表L<SPAN
class=down><sub>1</sub></SPAN>.nextlist中相应的转移指令的目标标号应被回填为M.quad,即S的代码的开始位置。 <p>
要注意的是,在上述语义规则中除了(2)和(5)以外,均未生成新的四元式。所有其它代码将由与赋值语句和表达式相连的语义规则产生。所谓控制流程,即在适当的时候进行回填,以便赋值和布尔表达式的求值得到合适的连接。
</td></tr></table>
<br>
<table align=right width=300>
<tr>
<td><img src="../images/previous.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='7.6.2b.htm'" ></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='7.6.2_2.htm'"></img></td>
</tr>
</table>
</BODY>
<html><script language="JavaScript">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -