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

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

<font class="title2"><b>2.3.3 二义性</b></font> 
<table><tr><td>&nbsp&nbsp&nbsp&nbsp</td> 
<td class="content"> 
<p> 
我们希望分析的过程是唯一的,即,对于一个文法G=(V<sub>T</sub>,V<sub>N</sub>,S,P)和一个符号串w,若w∈L(G),那么,S <img src="img\equalstar.gif"  width="20" height="23"> w唯一。但是,有些文法并非如此。例如,程序语言中对IF语句常用下面的文法:  
<table align=center width=400> 
<tr> 
<td align=right>S→</td> 
<td>if E then S </td> 
</tr> 
<tr> 
<td></td><td>|if E then S else S </td> 
</tr> 
<tr> 
<td></td><td>|other &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp(2.2) </td> 
</tr> 
</table> 
这里的"other"表示其它语句。根据这个文法,复合条件语句:<br>  
<center>if E1 then if E2 then S1 else S2&nbsp&nbsp&nbsp&nbsp (2.3) </center> 
有下面两个最左推导: <br> 
<table align=center width=400> 
<tr> 
<td align=right>S</td> 
<td> <img src="IMG/equal.gif"></img> if E1 then S</td> 
</tr> 
<tr> 
<td></td><td>  <img src="IMG/equal.gif"></img> if E1 then if E2 then S1 else S2 &nbsp&nbsp&nbsp&nbsp(2.4) </td> 
</tr> 
<tr> 
<td align=right>S</td> 
<td> <img src="IMG/equal.gif"></img> if E1 then S else S2</td> 
</tr> 
<tr> 
<td></td><td>  <img src="IMG/equal.gif"></img> if E1 then if E2 then S1 else S2&nbsp&nbsp&nbsp&nbsp (2.5) </td> 
</tr> 
</table> 
根据上面两个最左推导画出的分析树由图2.8给出。 
<p align=center> 
<img src="IMG/2.8.gif"> 
</p> 
<p> 
对于句子(2.3)来说,在程序语言中它的语义是唯一的,由图2.8(a)的分析树给出。那么,为什么会有两个最左推导,因而有两棵分析树呢?原因在于使用的文法(2.2)。  
</p> 
<p> 
<table> 
<tr> 
<td><font class="yanshi">&nbsp&nbsp&nbsp&nbsp观看演示&nbsp</font></td> 
<td><font color=blue onmouseover="javascript:style.cursor='hand'" onclick="javascript:open('APPLET/test2_2/Page1.htm','_blank','menu=no,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,left=100,top=100,width=800,height=600')">if_then_else的两种推导</font></td> 
<td><img src="../images/yanshi.gif"></img></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='2.3.2b.htm'"></img></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='2.3.3b.htm'"></img></td>
</tr> 
</table> 
 
</BODY> 
</html>

⌨️ 快捷键说明

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