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

📄 4.6.1.0c.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.6.1.0b.htm'"></img></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='4.6.2.0.htm'"></img></td>
</tr>
</table>
<br><br>
<table><tr>
<td class="content">            
<p>   
<font class="definition">算法4.5 </font> 算符优先分析法<br>   
&nbsp&nbsp&nbsp&nbsp输入:一个输入符号串w 和一张优先关系表。<br>    
&nbsp&nbsp&nbsp&nbsp输出:若w是一个句子,输出一棵分析树基架,否则输出一个错误信息。<br>   
&nbsp&nbsp&nbsp&nbsp方法:分别置放$到栈中和w$到输入缓冲器中,并执行图4.13所表示的程序。</p>   
<p>     (1)置ip, 使之指向w$的第一个符号;<br>    
        &nbsp;&nbsp;&nbsp;&nbsp;(2)<font color="#0000FF">repeat</font> <font color="#0000FF"> forever</font><br>   
        &nbsp;&nbsp;&nbsp;&nbsp;(3)&nbsp;&nbsp; <font color="#0000FF">if</font>  $在栈顶上并且ip指向$ 
t<font color="#0000FF">hen</font><br>   
        &nbsp;&nbsp;&nbsp;&nbsp;(4) &nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">return</font><br>   
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">else begin</font><br>    
        &nbsp;&nbsp;&nbsp;&nbsp;(5)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;令a是栈中最靠顶上的终结符号<br>   
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;并且令b是ip所指向的符号<br>   
        &nbsp;&nbsp;&nbsp;&nbsp;(6)&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<font color="#0000FF">if</font> a&lt;·b or     
        a<img src="images/equalpoint.gif" width="20" height="19">b <font color="#0000FF"> then begin</font><br>    
        &nbsp;&nbsp;&nbsp;&nbsp;(7)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;把b推入栈中;<br>   
        &nbsp;&nbsp;&nbsp;&nbsp;(8)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;使ip前进到下一个符号;<br>   
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">end</font>;<br>   
        &nbsp;&nbsp;&nbsp;&nbsp;(9)&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<font color="#0000FF">else if</font> a·&gt;b 
<font color="#0000FF">  then</font> /* 归约* /<br>    
        &nbsp;&nbsp;&nbsp;&nbsp;(10)&nbsp;&nbsp;&nbsp;&nbsp;     
        &nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">repeat</font><br>   
        &nbsp;&nbsp;&nbsp;&nbsp;(11)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;从栈中弹出符号<br>   
        &nbsp;&nbsp;&nbsp;&nbsp;(12)&nbsp;&nbsp;&nbsp;&nbsp;     
        &nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">until</font> 栈顶终结符号与最近弹出的符号之间有&lt;·关系成立<br>    
        &nbsp;&nbsp;&nbsp;&nbsp;(13)&nbsp;&nbsp; &nbsp;&nbsp;<font color="#0000FF">else</font> error( )<br>    
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000FF">end</font><br>   
        <center>图4.13算符优先分析算法</center>   
</p>   
   
<p>读者不难看到,在上述分析算法中起着重要作用的是终结符号。在每一个归约串中至少包含一个终结符号。非终结符号不影响分析。至于把非终结符号也保留在栈中,是让它为自己的属性值占一个位置。可以说,在上面的讨论和算法中,我们实质上用到了一个重要的概念和结论。下面我们叙述这个概念和结论,但不给出结论的证明。</p>   
<p>   
<img class="dingyi" src="../images/dingyi.gif"></img>   
<font class="definition2">定义4.6 </font> 设G是一个算符文法,β是句型αβδ关于A的短语(即有S<img src="images/equalstar.gif" width="20" height="19">αAδ且A<img src="images/equalplus.gif" width="20" height="19">β )且β至少含有一个终结符号,并且除自身之外不再含有任何更小的带有终结符号的短语,则称β是句型αβδ关于A的素短语。所谓最左素短语是指处于句型最左边的那个素短语。   
</p>   
<p>算符优先分析法中的可归约串,严格说来是指最左素短语。然而在二义性文法(4.13)的句子的分析中,每次的可归约串既是最左素短语,也是句柄。   
</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_5/Page1.htm','_blank','left=100,top=100,scrollbars=yes,resizable=yes,width=850,height=600')">算符优先分析法分析过程</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.6.1.0b.htm'"></img></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='4.6.2.0.htm'"></img></td>
</tr>        
</table>        
        
</BODY>        

<html><script language="JavaScript">

⌨️ 快捷键说明

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