📄 4.7.3.1b.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.1.htm'"></img></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='4.7.3.2.htm'"></img></td>
</tr>
</table>
<br><br>
<table><tr><td>    </td>
<td class="content">
<p>
<font class="definition">算法4.10 </font> 计算LR(1)的closure(I)和Go(I,x) <br>
<font color="#0000FF">FUNCTION</font> closure(I:SET OF
item):<font color="#0000FF">SET OF</font> item; <br>
<font color="#0000FF">BEGIN</font> <br>
<font color="#0000FF">REPEAT</font> <br>
<font color="#0000FF">FOR</font> 任一[A→α.Bβ,a]
<font color="#0000FF"> IN</font> I <br>
<font color="#0000FF">FOR</font> 任一B→η
<font color="#0000FF"> IN</font> P <br>
<font color="#0000FF">FOR</font> 任一b
<font color="#0000FF"> IN</font> <b>FIRST</b>(βa) <br>
I:=I∪{[B→.η,b]} <br>
<font color="#0000FF">UNTIL</font> I不再增大 <br>
<font color="#0000FF">Return</font> (I) <br>
<font color="#0000FF">END</font>; <br>
<br>
<font color="#0000FF">FUNCTION</font> Go(I:SET OF item; x∈{V<sub>T</sub>∪V<sub>N</sub>}):<font color="#0000FF">SET OF</font> item; <br>
<font color="#0000FF">VAR</font> J:<font color="#0000FF">SET OF</font> item; <br>
<font color="#0000FF">BEGIN</font> <br>
J:={ }; <br>
<font color="#0000FF">FOR</font> 任一[A→α.Xβ,a]
<font color="#0000FF"> IN</font> I <br>
J:=J∪{[A→αX.β,a]} <br>
<font color="#0000FF">Return</font> (closure(J)) <br>
<font color="#0000FF">END</font>; </p>
<p>我们现在给出LR(1)有效项目集族的构造算法。</p>
<p align="left">
<font class="definition">算法4.11 </font> LR(1)项目集规范族的构造 <br>
输入:一个拓广文法G' 。 <br>
输出: LR(1)的项目集规范族。 <br>
方法: LR(1)项目集规范族的构造如图4.22所示。 <br>
<br>
<font face="楷体_GB2312"><font color="#0000FF">procedure</font> items(G'); <br>
<font color="#0000FF">begin</font> <br>
C:={closure({[S'→·S,$]}) }; <br>
<font color="#0000FF">repeat</font> <br>
<font color="#0000FF">for</font> 每一个在C中的项目集I和每一个文法符号X <br>
如果go(I,X)不为空且不在C中do <br>
把go(I,X)加入到C中 <br>
<font color="#0000FF">until</font> 没有更多的项目集可被加入到C中 <br>
<font color="#0000FF">end</font> <br></font>
<font face="楷体_GB2312"> </font>图4. 22 关于文法G'的LR(1)项目集规范族的构造
</p>
</td></tr></table>
<table align=left>
<td><font class="yanshi">    观看演示 </font></td>
<td>
<font color=blue onmouseover="javascript:style.cursor='hand';" onclick="javascript:open('applet/test4_8/test4_8.html','_blank','left=100,top=100,scrollbars=yes,resizable=yes,width=850,height=600')">LR(1)项目集规范族的构造过程</font>
</td>
<td><img src="../images/yanshi.gif"></img></td>
</table>
<br>
<br>
<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.1.htm'"></img></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='4.7.3.2.htm'"></img></td>
</tr>
</table>
</BODY>
</html>
<html><script language="JavaScript">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -