📄 4.7.3.2b.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.7.3.2.htm'"></img></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='4.7.3.3.htm'"></img></td>
</tr>
</table>
<br><br>
<table><tr><td>    </td>
<td class="content">
<p>
<font class="definition">算法4.12 </font> LR(1)分析表的构造 <br>
输入:一个拓广文法G' 。 <br>
输出: 对于G'的LR(1)分析表。 <br>
方法:<br>
1. 利用图4.22构造G'的LR(1)有效项目集族C={I<sub>0</sub>,I<sub>1</sub>,…,I<sub>n</sub>}。<br>
2. 对于代表项目集I<sub>i</sub>的状态i,分析动作如下: <br>
(a)若[ A→α·aβ,b] 属于I<sub>i</sub> 且go(I<sub>i</sub>,a)=I<sub>j</sub>,则置 <br>
action[i,a]=s<sub>j</sub> <br>
(b)若[A→α·,a] 属于I<sub>i</sub> 且A≠S',则置 <br>
action[i,a]=r<sub>j</sub> <br>
(c)若[S'→S·,$] 属于I<sub>i</sub>,则置<br>
action[i,$] =acc <br>
其中s<sub>j</sub>,r<sub>j</sub>,acc的意义同SLR分析表。<br>
3.若对任何非终结符号A有go(I<sub>i</sub>,A)=I<sub>j</sub>,则置 <br>
goto[i,A]=j <br>
4.凡是分析表中不能用上述规则填入信息的空白格上均填上出错标志"error"。<br>
5. 分析器的初态是由包括[S'→·S,$] 的有效项目集所对应的状态。
</p>
<p>按上述算法构造的分析表,如果不存在多重定义的人口(即不存在动作冲突),则称它是文法G的一张LR(1)分析表。使用这张分析表的分析器,称为LR(1)分析器。具有LR(1)分析表的文法,称为一个LR(1)文法。</p>
</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.7.3.2.htm'"></img></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='4.7.3.3.htm'"></img></td>
</tr>
</table>
</BODY>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -