📄 2.3.2.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.1d.htm'"></img></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='2.3.2b.htm'"></img></td>
</tr>
</table>
<br><br>
<font class="title2"><b>2.3.2 分析树的构造</b></font>
<table><tr><td>    </td>
<td class="content">
<p>
<b>1.根据推导构造分析树</b>
</p>
<p>
已知文法G[S],对于w,若w∈L(G),则存在一个推导序列S <img src="IMG/equal.gif"></img> w。分析树的构造步骤如下:
</p>
<p>
首先,设置以开始符号S为标识的根结点,然后,对每进行的一步推导,根据使用的产生式,生成一子树,直至推导结束。设推导使用的产生式为A→x<sub>1</sub>x<sub>2</sub>...x<sub>n</sub>,则生成以A为根结点,从左至右,标识为x<sub>1</sub>,x<sub>2</sub>,...,x<sub>n</sub>的子结点的一棵子树。例如,对于例2.6的文法G和句子aabbaa,其推导和构造分析树的过程看相应演示。
</p>
<p>
<table align=center >
<tr><td align=left valign=top>
<font size=5>S <img src="img/equal_one.gif"> aAS(S→aAS)<br>
  <img src="img/equal_two.gif"> aSbAS(A→SbA)    <br>
  <img src="img/equal_three.gif"> aabAS(S→a)<br>
  <img src="img/equal_four.gif"> aabbaS(A→ba)<br>
  <img src="img/equal_five.gif"> aabbaa(S→a)</td>
<td><img src="img\2.6(2).gif" ></td></tr>
</table>
</p>
<p>
上面构造树的过程,是从树根开始,每进行一步推导,就生出某一子树的子结点,直至推导结束。这种画树过程是从树根到树叶。对于一个w,我们把构造S <img src="IMG/equal.gif"></img> w称作句法(语法)分析,上面这种分析过程称为自顶向下分析。
</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.3.1d.htm'"></img></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='2.3.2b.htm'"></img></td>
</tr>
</table>
</BODY>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -