📄 5.1.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.1.2.htm'"></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='5.1.3b.htm'"></img></td>
</tr>
</table>
<br><br>
<font class="title2"><b>5.1.3 继承属性</b></font>
<table>
<tr>
<td>    </td>
<td class="content">
<p>
在一棵分析树中的一个结点的继承属性值是由此结点的父结点和/或兄弟结点的某些属性来决定的。用继承属性来表示程序设计语言上下文的结构关系是很方便的。例如,我们可以利用一个继承属性来跟踪了解一个标识符究竟出现在一个赋值符号的右边还是左边,以确定是需要这个标识符的值还是它的地址。尽管我们有可能仅用综合属性来改写一个语法制导定义,但是使用带有继承属性的语法制导定义更为自然。
</p>
</td>
</tr>
</table>
<table><tr><td>    </td>
<td class="content">
<p>
在下面的例子中,继承属性在说明中为各种标识符提供类型信息。
</p>
</td>
</tr>
</table>
<p align=center>表5.2 带有继承属性L.in的语法制导定义</p>
<table align = center border = 1 width = "60%" cellspacing="0" cellpadding="5">
<tr>
<td width = "40%"><div align = center>产生式</div></td>
<td width = "60%"><div align = center>语义规则</div></td>
</tr>
<tr>
<td width = "40%">
<p>D -> TL</p>
<p>T -> int</p>
<p>T -> real</p>
<p>L -> L<sub>1</sub>,id</p>
<p> </p>
<p>L -> id</p>
<p></p>
</td>
<td width = "60%">
<p>L.in := T.type</p>
<p>T.type := integer</p>
<p>T.type := real</p>
<p>L<sub>1</sub>.in := L.in</p>
<p>addtype(id.entry,L.in)</p>
<p>addtype(id.entry,L.in)</p>
<p></p>
</td>
</tr>
</table>
<br>
<table><tr><td>    </td>
<td class="content">
<p>
<b>例5.3</b> 表5.2的语法制导定义中由非终结符号D产生的说明包含了类型关键字int或real,后面跟一个标识符表。非终结符号T有一个综合属性type,它的值是由说明中的关键字来确定的。语义规则L.in:=T.type对应于产生式D→TL,它把说明中的类型赋给继承属性L.in。语义规则使用继承属性L.in把这个类型信息在分析树中向下传递。与L的产生式相联系的语义规则调用过程addtype,它把类型赋给每个标识符在符号表中相应的表项中(由属性entry指出)。
</p>
</td>
</tr>
</table>
<table>
<tr>
<td><font class="yanshi">     观看演示 </font></td>
<td><font color=blue onmouseover="javascript:style.cursor='hand'" onclick="javascript:open('compile5_1/compile.html','_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>
<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.1.2.htm'"></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='5.1.3b.htm'"></img></td>
</tr>
</table>
</BODY>
<html><script language="JavaScript">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -