📄 4.2.3.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='4.2.3.2b.htm'"></img></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='4.2.3.3b.htm'"></img></td>
</tr>
</table>
<br><br>
<table><tr><td>    </td>
<td class="content">
<p><font class="emphasize">预测分析表的构造</font></p>
<p>在对文法G的每个非终结符号A及其任意候选α都构造出<b>FIRST</b>(α)和<b>FOLLOW</b>(A)之后,我们现在可以用它们来构造G的分析表M[A,a]。构造分析表算法的思想背景是很简单的。例如,假定A→α是一个产生式,a∈<b>FIRST</b>(α)。那么,当A呈现于栈顶且a是当前输入符号时,α应被当作是A唯一合适的代表。因此,第一个下标为A,第二个下标为a的矩阵元素M[A,a] 中应放进产生式A→α。复杂一点的情况是,当α<img src="images/equalstar.gif" width="20" height="19">ε时所发生的。在此情况下,如果当前面临的输入符号a(也包括$)属于<b>FOLLOW</b>(A),那么,A→α就认为已自动得到匹配,因而应把A→α放在M[A,a]中。根据这个思想背景,构造分析表M 的算法表示如下。</p>
<p>
<font class="definition"><img border="0" src="images/dingyi.gif" width="32" height="31">算法4.3 预测分析表的构造</font>
<br>
<p>输入:文法G</p>
<p>输出:分析表M</p>
<p>方法:</p>
<p>1.对文法G的每个产生式A→α 执行第2步和第3步;</p>
<p>2.对每个终结符号a∈<b>FIRST</b>(α),把A→α加至M[A,a] 中;</p>
<p>3. 若α<img src="images/equalstar.gif" width="20" height="19">ε,则对任何b∈<b>FOLLOW</b>(A),把A→α 加至M[A,b]中;</p>
<p>4.把所有无定义的M[A,a]标上错误标志。</p>
<p><font class="example">例4.6</font> 让我们将算法4.3应用到文法(4.3)。考虑产生式E→TE'。因为</p>
<p align="center"><b>FIRST</b>(TE') =<b>FIRST</b>(T)= {(,id}</p>
<p>所以产生式E→TE'应加至M[E,(]和M[E,id] 之中。同样,因为+∈<b>FIRST</b>(+TE'),产生式E'→+TE'应加至M[E',+]中。由于<b>FOLLOW</b>(E')={),$},产生式E'→ε应加至M[E',)]和M[E',$] 之中。按照算法4.3所构造的关于文法(4.3)的分析表如表4.1所示。</p>
</td></tr></table>
<table align=right width=300>
<tr>
<td><img src="../images/previous.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='4.2.3.2b.htm'"></img></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='4.2.3.3b.htm'"></img></td>
</tr>
</table>
</BODY>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -