📄 5.5.2_1b.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='5.5.2_1.htm'" width="24" height="24"></img></td>
<td>
<img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='5.6.0.htm'" width="26" height="24"></img></td>
</tr>
</table>
<br><br>
<table><tr><td>    </td>
<td class="content">
产生式R的代码基于图5.19的分析过程。若向前看符号是<b>addop</b>,那么,应用产生式R→<b>addop</b>
T R,通过过程match读人<b>addop</b>之后的下一个输入符号,然后再调用T
和R的函数。否则,过程将什么也不做以模仿R→ε。
</td>
</tr>
</table>
<table><tr><td>    </td>
<td class="content">
<p>
<b> <font color="#0000FF">procedure</font></b> R;<br>
<b> <font color="#0000FF">begin</font></b><br>
<b> <font color="#0000FF">if</font></b>
lookahead=<b>addop <font color="#0000FF"> then begin</font></b><br>
match(<b>addop</b>);T;R<br>
<b> <font color="#0000FF">end<br>
else
begin</font></b> <br>
<font color="#008000">/*do nothing*/</font><br>
<b> <font color="#0000FF">end</font><br>
<font color="#0000FF">end</font></b>;<br>
<br>
<font face="楷体_GB2312">
图5.19 产生式R->addop T R|ε的分析过程</font>
</p>
</td>
</tr>
</table>
<table><tr><td>    </td>
<td class="content">
<p>
在图5.20中的对应于R的函数过程包含计算属性的代码。符号<b>addop</b>的词法值lexval存放在addoplexeme中,<b>addop</b>被匹配,调用函数T,它的结果被存放在nptr中。变量i<span class="down"><sub>1</sub></span>对应于(5.5)中的继承属性R<span class="down"><sub>1</sub></span>.i,s<span class="down"><sub>1</sub></span>对应于综合属性R<span class="down"><sub>1</sub></span>.s。返回语句return
s正好在控制离开函数以前返回s的值。对于E和T的函数同样构造。
</p>
</td>
</tr>
</table>
<table width="596"><tr><td width="16">    </td>
<td class="content" width="566">
<p>
<b> <font color="#0000FF">function</font></b> R(in:↑syntax-tree-node):↑syntax-tree-node;<br>
<b> <font color="#0000FF">var</font></b>
nptr,i<sub>1</sub>,s<sub>1</sub>,s;↑syntax-tree-node;<br>
addoplexeme:<b><font color="#0000FF">char</font></b>;<br>
<b> <font color="#0000FF">begin</font></b><font color="#0000FF"><br>
<b> if</b>
</font>
lookahead=<b>addop <font color="#0000FF"> then begin</font></b><br>
<font color="#008000">/*产生式R→<b>addop</b>
T R*/</font><br>
addoplexeme:=lexval;<br>
match(<b>addop</b>);<br>
nptr:=T;<br>
i<span class="down"><sub>1</sub></span>:=mknode(addoplexeme,in,nptr);<br>
s<span class="down"><sub>1</sub></span>:=R(i<span class="down"><sub>1</sub></span>);<br>
s:=s<span class="down"><sub>1</sub></span><br>
<b> <font color="#0000FF">end</font></b><font color="#0000FF"><br>
<b> else</b>
</font>
s:=in; <font color="#008000"> /*产生式R->ε*/</font><br>
<b> <font color="#0000FF">return</font></b>
s<br>
<b> <font color="#0000FF">end</font></b>;<br>
<br>
<font face="楷体_GB2312">
图5.20 递归下降构造语法树</font>
</p>
</td>
</tr>
</table>
<br>
<br>
<table align=right width=300>
<tr>
<td>
<img src="../images/previous.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='5.5.2_1.htm'" width="24" height="24"></img></td>
<td>
<img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='5.6.0.htm'" width="26" height="24"></img></td>
</tr>
</table>
</BODY>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -