📄 4.6.1.0c.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>
    输入:一个输入符号串w 和一张优先关系表。<br>
    输出:若w是一个句子,输出一棵分析树基架,否则输出一个错误信息。<br>
    方法:分别置放$到栈中和w$到输入缓冲器中,并执行图4.13所表示的程序。</p>
<p> (1)置ip, 使之指向w$的第一个符号;<br>
(2)<font color="#0000FF">repeat</font> <font color="#0000FF"> forever</font><br>
(3) <font color="#0000FF">if</font> $在栈顶上并且ip指向$
t<font color="#0000FF">hen</font><br>
(4) <font color="#0000FF">return</font><br>
<font color="#0000FF">else begin</font><br>
(5) 令a是栈中最靠顶上的终结符号<br>
并且令b是ip所指向的符号<br>
(6) <font color="#0000FF">if</font> a<·b or
a<img src="images/equalpoint.gif" width="20" height="19">b <font color="#0000FF"> then begin</font><br>
(7) 把b推入栈中;<br>
(8) 使ip前进到下一个符号;<br>
<font color="#0000FF">end</font>;<br>
(9) <font color="#0000FF">else if</font> a·>b
<font color="#0000FF"> then</font> /* 归约* /<br>
(10)
<font color="#0000FF">repeat</font><br>
(11) 从栈中弹出符号<br>
(12)
<font color="#0000FF">until</font> 栈顶终结符号与最近弹出的符号之间有<·关系成立<br>
(13) <font color="#0000FF">else</font> error( )<br>
<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">    观看演示 </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 + -