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

📄 4.2.3.0b.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.2.3.0.htm'"></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='4.2.3.1.htm'"></img></td>
</tr>
</table>
<br><br>
<table><tr><td>&nbsp&nbsp&nbsp&nbsp</td>           
<td class="content">  
<br><p>       
预测分析器的控制程序的工作如下。此程序总是根据栈顶符号X和当前输入符号a来决定分析器的动作。有三种可能的动作:</p>       
<p>1.若X=a=$,则分析器停止分析,宣布分析成功。</p>    
<p>2. 若X=a≠$,则分析器把X从栈顶弹出,让输入指针指向下一个输入符号。</p>       
<p>3. 若X是一个非终结符号,则查阅分析表M。若在M[X,a]中存放着关于X的一个产生式,那么,首先把X从栈顶弹出,然后把产生式的右部符号串按反序一一推进栈中。例如,若M[X,a]={x→UVW},分析器把在栈顶的X换为WVU,即U在栈顶。若M [X,a]={X→ε},分析器把在栈顶的X弹出即可。作为输出,我们假定分析器只印出要采用的产生式;事实上可以包括任何其它在这里能被执行的代码。若M[X,a]=error(出错标志)则调用出错处理程序。<br><br></p>   
</td></tr>
<tr><td>&nbsp&nbsp&nbsp&nbsp</td>           
<td >
<table border=0>
	<tr>
		<td width=100>&nbsp;</td>
		<td>
<p>置ip指向w$的第一个符号<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<font color="#0000FF">repeat</font><br> 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 令X是栈顶符号,a是ip所指向的符号;<br>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; <font color="#0000FF">if</font> X是一个终结符号或$<font color="#0000FF">then</font><br> 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; <font color="#0000FF">if</font> X=a  
<font color="#0000FF"> 
then</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 把x从栈中弹出,并且更新ip<br>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#0000FF">else</font>   
error()<br> 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#0000FF">else</font><font color="#008000">/* X是非终结符号 */</font><br>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#0000FF">if</font> M[X,a]=x→Y<sub>1</sub>Y<sub>2</sub>…Y<sub>k</sub>   
 <font color="#0000FF">  
then begin</font><br> 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   
把X从栈中弹出;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   
把Y<sub>k</sub>,Y<sub>k-1</sub>,…, Y<sub>1</sub>压入栈中,即Y<sub>1</sub>在顶上;<br>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   
输出产生式X→Y<sub>1</sub>Y<sub>2</sub>…Y<sub>k</sub><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#0000FF">end</font><br> 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#0000FF">else</font> error()<br>  
&nbsp;&nbsp;&nbsp;<font color="#0000FF">&nbsp;until</font> X=$ <font color="#008000"> /* 栈为空 */</font></p>  
<p align="center">图4.8 预测分析控制程序</p>
		</td>
	</tr>
</table>
</td></tr></table>  
    
     
<br>     
<table align=right width=300>     
<tr>     
<td><img src="../images/previous.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='4.2.3.0.htm'"></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='4.2.3.1.htm'"></img></td>
</tr>     
</table>     
     
</BODY>     
</html>

⌨️ 快捷键说明

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