📄 2.2.2i.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.2.2h.htm'"></img></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='2.2.2j.htm'"></img></td>
</tr>
</table>
<br><br>
<table><tr><td>    </td>
<td class="content">
<p>
<font class="example">例2.5 </font>我们将说明符号串(a*a+a)是文法(2.1)(文法G)的句子。这是因为有如下的推导:<br>
<center>E <img src="IMG/equal.gif"></img> T <img src="IMG/equal.gif"></img> F <img src="IMG/equal.gif"></img> (E) <img src="IMG/equal.gif"></img> (E+T) <img src="IMG/equal.gif"></img> (T+T) </center>
<center>  <img src="IMG/equal.gif"></img> (T*F+T) <img src="IMG/equal.gif"></img> (F*F+T) <img src="IMG/equal.gif"></img> (a*F+T)   </center>
<center>  <img src="IMG/equal.gif"></img> (a*a+T) <img src="IMG/equal.gif"></img> (a*a+F) <img src="IMG/equal.gif"></img> (a*a+a)   </center>
</p>
<p>
根据句子的定义,终结符号串(a*a+a)是文法G的句子。而T,F,(E),(E+T),(T+T),(T*F+T),(F*F+T),(a*F+T),(a*a+T),(a*a+F)都是文法G的句型。L(G)则是文法G产生的所有表达式(文法G产生的所有句子)所组成的集合。
</p>
<p>
请注意在上述例子的推导过程中任何一步α<img src="IMG/equal.gif"></img>β都是对α中的最左非终结符号进行替换的,我们称这样的推导为<font class="emphasize2">最左推导</font>。可以把最左推导中用到的<img src="IMG/equal.gif"></img>均写作<img src="img\equallm.gif" width=25 height=19>。如果在推导过程中的任何一步都是对α中的最右非终结符号进行替换,则称这样的推导为<font class="emphasize2">最右推导</font>。可以把最右推导中用到的<img src="IMG/equal.gif"></img>均写作<img src="img\equalrm.gif" width=25 height=19>。
</p>
<p>
上述例题中的符号串(a*a+a)也可以由最右推导得到:<br>
<table align=center width=80%>
<tr>
<td width=10% align=right>E</td>
<td><img src="img\equalrm.gif" width=25 height=19>T<img src="img\equalrm.gif" width=25 height=19>F<img src="img\equalrm.gif" width=25 height=19>(E)<img src="img\equalrm.gif" width=25 height=19>(E+T)</td>
</tr>
<tr>
<td></td>
<td><img src="img\equalrm.gif" width=25 height=19>(E+F)<img src="img\equalrm.gif" width=25 height=19>(E+a)<img src="img\equalrm.gif" width=25 height=19>(T+a)</td>
</tr>
<tr>
<td></td>
<td><img src="img\equalrm.gif" width=25 height=19>(T*F+a)<img src="img\equalrm.gif" width=25 height=19>(T*a+a)<img src="img\equalrm.gif" width=25 height=19>(F*a+a)</td>
</tr>
<tr>
<td></td>
<td><img src="img\equalrm.gif" width=25 height=19>(a*a+a) </td>
</tr>
</table>
</p>
<p>
由此看出,从一个句型到另一个句型的推导往往不是唯一的。如从E到(a*a+a)的推导,除以上两种推导外,还存在其它的推导。今后为了对句子的结构进行确定的分析,我们一般只考虑最左推导或最右推导。
</p>
<p>
<table>
<tr>
<td><font class="yanshi">    观看演示 </font></td>
<td><font color=blue onmouseover="javascript:style.cursor='hand'" onclick="javascript:open('APPLET/test2_1/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')">最左推导和最右推导(可接受输入)</font></td>
<td><img src="../images/yanshi.gif"></img></td>
</tr>
</table>
</p>
</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.2.2h.htm'"></img></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='2.2.2j.htm'"></img></td>
</tr>
</table>
</BODY>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -