📄 4.3.1.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='4.3.1.1b.htm'"></img></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='4.3.1.2b.htm'"></img></td>
</tr>
</table>
<br><br>
<table><tr><td>    </td>
<td class="content">
<p><font class="example">例4.8 </font>应用算法4.4到文法(4.7)。因为文法(4.7)带有ε- 产生式,所以要首先改写文法(4.7)为ε-无关文法。只有非终结符号A能产生ε。根据上述算法,文法(4.7)的改写如表4.6所示。</p>
</td></tr></table>
<p>
<center><img src="images/table4.62.gif" width="474" height="266"></center><br>
</p>
<table><tr><td>    </td>
<td class="content">
<p>现在考虑对改写后的文法:</p>
<table align=center width=450 class="content">
<tr><td>S→Aa|a|b</td></tr>
<tr><td>A→Ac|c|Sd</td></tr>
</table>
<p>消除左递归。根据算法4.4,首先,我们把非终结符号的顺序安排为S,A 。对于S ,不存在直接左递归,所以图4.10中的第2步在i=1的情况下不作任何工作。当i= 2时,我们把S→Aa|a|b代入到A 的有关候选式后,得到</p>
<table align=center width=450 class="content">
<tr><td>A→Ac|c| Aad|ad|bd</td></tr>
</table>
<p>再消除A- 产生式中的直接左递归得到下面的文法:</p>
<table align=center width=450 class="content">
<tr><td>S→Aa|a|b</td></tr>
<tr><td>A→cA'|adA'|bdA'</td></tr>
<tr><td>A'→cA'|adA'|ε</td></tr>
</table>
</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='4.3.1.1b.htm'"></img></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='4.3.1.2b.htm'"></img></td>
</tr>
</table>
</BODY>
</html>
<html><script language="JavaScript">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -