📄 7.4.3b.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.3.htm'" width="24" height="24" ></td>
<td>
<img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'"
onclick="vbscript:window.location.href='7.4.3c.htm'" width="26" height="24" ></td>
</tr>
</table>
<p><br>
<br>
<table>
<tr>
<td> </td>
<td class="content">在翻译if-then语句S→<b>if</b> E <b>then</b> S<span class="down">1</span>时,我们建立了一个新的标号E.true,并且用它来标识关于S<span
class="down">1</span>的代码的第一条指令,如图7.13(a)所示。表7.4给出了一个语法制导定义。在E的代码中将有这样的转移指令:若E为真则转移到E.true,并且若E为假则转移到S.next因此我们置E.false为S.next.
<p align="center"><br>
表7.4 控制流语句的语法制导定义<br>
</p>
<table width="85%" align="center" border="1" cellspacing="0" cellpadding="0">
<tr>
<td width="40%" height="30" align="center">产生式</td>
<td width="60%" align="center">语义规则</td>
</tr>
<tr>
<td align="left" valign="top"><br>
<p>S -><b>if</b> E <b>then</b> S<sub>1</sub></p>
<p><br>
<br>
<br>
<br>
<br>
</p>
<p>S -><b>if</b> E <b>then</b> S<sub>1</sub><br>
<b>else</b> S<sub>2</sub></p>
<p><br>
<br>
<br>
<br>
<br>
<br>
<br>
</p>
<p>S -><b>while</b> E <b>do</b> S<sub>1</sub></td>
<td align="left" valign="top"><br>
E.true := newlabel;<br>
E.false := S.next;<br>
S<sub>1</sub>.next := S.next<br>
S.code := E.code ||<br>
gen(E.true ':') || S<sub>1</sub>.code<br>
<br>
E.true := newlabel;<br>
E.false := newlabel;<br>
S<sub>1</sub>.next := S.next<br>
S<sub>2</sub>.next := S.next;<br>
S.code := E.code ||<br>
gen(E.true ':') || S<sub>1</sub>.code
||gen('goto' S.next) ||<br>
gen(E.false ':') || S<sub>2</sub>.code
<br>
<br>
S.begin := newlabel;<br>
E.true := newlabel;<br>
E.false := S.next<br>
S<sub>1</sub>.next := S.begin<br>
S.code := gen(S.begin ':') <br>
|| E.code ||gen(S.true ':') <br>
|| S<sub>1</sub>.code <br>
||gen('goto' S.begin) <br>
</td>
</tr>
</table>
</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.3.htm'" width="24" height="24" ></td>
<td>
<img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'"
onclick="vbscript:window.location.href='7.4.3c.htm'" width="26" height="24" ></td>
</tr>
</table>
</body>
</html>
<html><script language="JavaScript">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -