📄 7.6.2_2.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.2c.htm'" ></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'"
onclick="vbscript:window.location.href='7.6.2_2b.htm'" ></td>
</tr>
</table>
<p><br>
<br>
</p>
<table>
<tr>
<td class="content"><font class="example">例7.6</font>
考虑使用自底向上的分析法按照上述翻译模式生成下述语句表(语句序列)的四元式目标代码,其中A<sub>1</sub>,A<sub>2</sub>和A<sub>3</sub>
均表示赋值语句。 <p>if a<b or c<d and e<f then A<sub>1</sub> else A<sub>2</sub>;while
a<b do A<sub>3</sub> </p>
<p>我们可以按照下列各步来得到所求的四元式代码: </p>
<p>(a)我们将用到的产生式主要有模式中的(l)和(5),即 </p>
<p>S→if E then M<sub>1</sub> S<sub>1</sub> N else M<sub>2</sub> S<sub>2</sub> </p>
<p>S while M<sub>1</sub> E do M<sub>2</sub> S<sub>1</sub><span class="down"><br>
</span>并且其它与此有关的产生式也将用到。例中的布尔表达式a<b
orc<d and e<f与例7.5的相同。因而将首先生成下列四元式(我们仍从编号100开始):
</p>
<br> 100: if a<b goto—
<br> 101: goto l02
<br> 102: if c<d goto l04
<br> 103: goto—
<br> 104:if a<f goto— <F goto—>
<br> 105: goto—
<br> (b)当未到达相当于S<sub>1</sub>的赋值语句A<span class="down">1</span>之前,有一个M<sub>1</sub>,此时的语义动作为:
<br> {M.quad :=nextquad}<br>
由于现在的最后一条四元式的编号为105,所以M<sub>1</sub>.quad之值为106。
<br> (c)分析到赋值语句A<sub>1</sub>。为了说明得具体些,我们不妨假设当人归约为S<sub>1</sub>时,A<sub>1</sub>本身已产生了10条四元式指令(这一点翻译模式中没有),即有</p>
<br> 106:
<div align="right"><table border="0" width="100%">
<TBODY>
<tr>
<td width="18%"> .</td>
<td width="82%"></td>
</tr>
<tr>
<td width="18%"> .</td>
<td width="82%">关于A<sub>1</sub>的四元式 } 共10条</td>
</tr>
<tr>
<td width="18%"> .</td>
<td width="82%"></td>
</tr>
</TBODY>
</table>
</div>
<br> 115: </p>
<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.6.2c.htm'" ></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'"
onclick="vbscript:window.location.href='7.6.2_2b.htm'" ></td>
</tr>
</table>
</body>
</html>
<html><script language="JavaScript">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -