📄 4.3.1.0b.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.0.htm'"></img></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='4.3.1.1.htm'"></img></td>
</tr>
</table>
<br><br>
<table><tr><td>    </td>
<td class="content">
<p>如果用这样的规则构造递归预测分析的过程,那么,一进入这种过程,不匹配任何输入符号,直接执行递归调用,形成自己调用自己的死循环。间接左递归规则用于自顶向下分析也会出现类似的情形,所以,在左递归文法上进行消除左递归的变换是必要的。 </p>
<p><font class="emphasize">消除直接左递归</font></p>
<p>下面关于非终结符号A的规则是直接左递归规则:</p>
<p align="center">A→Aα|β</p>
<p>其中α,β∈(V<sub>T</sub>∪V<sub>N</sub>)<sup>*</sup>。若β不以A打头,可以把A的规则改写为如下非左递归规则:</p>
<table align=center width=450 class="content">
<tr><td>A→βA'</td></tr>
<tr><td>A'→αA'|ε</td></tr>
</table>
<p>其中,A'是新增加的非终结符号。例如,文法G[E](4.6)经消除直接左递归后,变换成文法G[E](4.3)。</p>
<p>一般而言,假定关于A的全部产生式是</p>
<table align=center width=450 class="content">
<tr><td>A→Aα<sub>1</sub>|Aα<sub>2</sub>|...|Aα<sub>m</sub>|β<sub>1</sub>|β<sub>2</sub>|...|β<sub>n</sub></td></tr>
</table>
<p>其中β<sub>i</sub>(i= 1,2,…,n)不以A打头;α<sub>j</sub>(j= 1,2,…,m )不等于ε。那么可以把上述产生式改写为</p>
<table align=center width=450 class="content">
<tr><td>A→β<sub>l</sub>A'|β<sub>2</sub>A'|…|β<sub>n</sub>A'</td></tr>
<tr><td>A'→α<sub>1</sub>A'|α<sub>2</sub>A'|…|α<sub>m</sub>A'|ε</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.0.htm'"></img></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='4.3.1.1.htm'"></img></td>
</tr>
</table>
</BODY>
</html>
<html><script language="JavaScript">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -