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

📄 4.7.1.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.1.1.htm'"></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='4.7.2.0.htm'"></img></td>
</tr>
</table>
<br><br>
<table><tr><td>&nbsp&nbsp&nbsp&nbsp</td> 
<td class="content">  
<p>前面的讨论可归纳为如下的算法。</p>   
<p>
<font class="definition">算法4.7 </font>LR分析算法<br>
&nbsp&nbsp&nbsp&nbsp输入:一个输入串w 和文法G的一张LR分析表。<br>  
&nbsp&nbsp&nbsp&nbsp输出:若w∈L(G),对于w的一个自底向上的分析;否则,一个错误表示。<br>
&nbsp&nbsp&nbsp&nbsp方法:开始时s<sub>0</sub>在栈中,且w$在输入缓冲器中。LR分析器执行图4.16的程序,直至遇到一个接受动作或错误动作为止。</p>  
</td></tr></table> 
	<table>
		<tr>
			<td width=100>&nbsp;</td>
			<td>
<p><font face="楷体_GB2312">置ip指向w$的第一个符号;<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">repeat</font> forever <font color="#0000FF"> begin</font><br>   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;令s是栈顶状态,并且a是ip所指向的符号;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">if</font> action[s,a]=shift s' 
<font color="#0000FF"> then begin</font><br>    
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;把a 和s'先后推人栈中;<br>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;使ip前进到下一个符号<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">end</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">else if</font> action[s,a]=reduce A→β 
<font color="#0000FF"> then begin</font><br>    
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;从栈顶弹出2*|β|个符号;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;令s'是当前栈顶状态;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;把A和goto[s',A]先后推入栈中;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;输出产生式A→β<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">end</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">else if</font> action[s,a]=accept 
<font color="#0000FF"> then</font><br>   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#0000FF">return</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">eIse </font> error()<br>   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">end</font><br><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;图4.16 LR分析程序</font></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_6/Page1.htm','_blank','left=100,top=100,scrollbars=yes,resizable=yes,width=850,height=600')">SLR分析器的分析过程</font>
</td>
<td><img src="../images/yanshi.gif"></img></td>
</table>     
<br><br><br>
<p>下面我们将说明如何从一个给定文法来构造LR分析表。在4.7.2节中将介绍简单的LR的分析表的构造。简单的LR简称SLR。在LR分析技术中,SLR的能力是最弱的,然而是最容易实现的。在4.7.3节中将讨论规范的LR的分析表的构造,特别是LR(l)分析表的构造。规范的LR分析技术是在SLR基础上的扩充。它的能力很强,当然实现起来代价也高。</p>

     
<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.1.0.htm'"></img></td>     
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='4.7.2.0.htm'"></img></td>     
</tr>     
</table>     
     
</BODY>     

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -