⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 4.7.3.1b.htm

📁 建立《编译原理网络课程》的目的不仅使学生掌握构造编译程序的原理和技术
💻 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>&nbsp&nbsp&nbsp&nbsp</td> 
<td class="content">  
<p>
<font class="definition">算法4.10 </font> 计算LR(1)的closure(I)和Go(I,x) <br>
	&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">FUNCTION</font> closure(I:SET OF 
item):<font color="#0000FF">SET OF</font> item; <br>   
	&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">BEGIN</font> <br>
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">REPEAT</font> <br>
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">FOR</font> 任一[A→α.Bβ,a] 
<font color="#0000FF"> IN</font> I <br>   
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">FOR</font> 任一B→η 
<font color="#0000FF"> IN</font> P <br>   
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">FOR</font> 任一b 
<font color="#0000FF"> IN</font> 	<b>FIRST</b>(βa) <br>   
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;I:=I∪{[B→.η,b]} <br>
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">UNTIL</font> I不再增大 <br>   
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">Return</font> (I) <br>   
	&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">END</font>; <br>
	&nbsp;&nbsp;&nbsp;&nbsp;<br>
        &nbsp;&nbsp;&nbsp;&nbsp;<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>   
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">VAR</font> J:<font color="#0000FF">SET OF</font> item; <br>   
        &nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">BEGIN</font> <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;J:={ }; <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">FOR</font> 任一[A→α.Xβ,a] 
<font color="#0000FF"> IN</font> I <br>   
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;J:=J∪{[A→αX.β,a]} <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">Return</font> (closure(J)) <br>   
        &nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">END</font>; </p>   

<p>我们现在给出LR(1)有效项目集族的构造算法。</p>
<p align="left">
<font class="definition">算法4.11 </font> LR(1)项目集规范族的构造  <br>
        &nbsp;&nbsp;&nbsp;&nbsp;输入:一个拓广文法G' 。 <br>   
        &nbsp;&nbsp;&nbsp;&nbsp;输出: LR(1)的项目集规范族。 <br>   
        &nbsp;&nbsp;&nbsp;&nbsp;方法: LR(1)项目集规范族的构造如图4.22所示。 <br>   
        <br>
        &nbsp;&nbsp;<font face="楷体_GB2312"><font color="#0000FF">procedure</font> items(G'); <br> 
        &nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">begin</font> <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;C:={closure({[S'→·S,$]}) }; <br> 
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">repeat</font> <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">for</font> 每一个在C中的项目集I和每一个文法符号X <br> 
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如果go(I,X)不为空且不在C中do <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;把go(I,X)加入到C中 <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">until</font> 没有更多的项目集可被加入到C中 <br> 
        &nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">end</font> <br></font>
<font face="楷体_GB2312">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font>图4. 22 关于文法G'的LR(1)项目集规范族的构造 
</p>  
</td></tr></table>  
<table align=left>
<td><font class="yanshi">&nbsp&nbsp&nbsp&nbsp观看演示&nbsp</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 + -