📄 5.2.3.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.2.2b.htm'" ></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='5.2.3b.htm'"></img></td>
</tr>
</table>
<br><br>
<font class="title2"><b>5.2.3 建立语法树的语法制导定义</b></font>
<table>
<tr>
<td>    </td>
<td class="content">
<p>
表5.3是一个为包含运算符号+和一的表达式建立语法树的S-属性定义。它利用文法的基本产生式来安排函数mknode和mkleaf的调用以建立语法树。E和T的综合属性nptr是函数调用返回的指针。
</p>
</td>
</tr>
</table>
<p align = center>表5.3 为表达式建立语法树的语法制导定义</p>
<table align = center border = 1 width = 85%" cellspacing="0" cellpadding="5">
<tr>
<td width = "24%"><div align = center>产生式</div></td>
<td width = "76%"><div align = center>语义规则</div></td>
</tr>
<tr>
<td width = "24%">
<p>E -> E<sub>1</sub>+T</p>
<p>E -> E<sub>1</sub>-T</p>
<p>E -> T</p>
<p>T -> (E)</p>
<p>T -> id</p>
<p>T -> num</p>
</td>
<td width = "76%">
<p>E.nptr := mknode( '+',E<sub>1</sub>.nptr,T.nptr)</p>
<p>E.nptr := mknode( '-',E<sub>1</sub>.nptr,T.nptr)</p>
<p>E.nptr := T.nptr</p>
<p>T.nptr := E.nptr</p>
<p>T.nptr := mkleaf(id,id.entry)</p>
<p>T.nptr := mkleaf(num,num.val)</p>
</td>
</tr>
</table>
<br>
<table><tr><td>    </td>
<td class="content">
<p>
<b>例5.8</b> 图5.7是一个带注释的分析树,它用来描绘表达式a-4+c的语法树的构造。分析树是用虚线表示的。分析树之中的E和T标识的结点用综合属性nptr来保存指向语法树中非终结符号代表的表达式结点的指针。
</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='5.2.2b.htm'" ></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='5.2.3b.htm'"></img></td>
</tr>
</table>
</BODY>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -