📄 5.6.3b.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.6.3.htm'"></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='5.6.3_1.htm'"></img></td>
</tr>
</table>
<br><br>
<center><img src="images/5_22.gif"></center><br>
<p align=center>图5.22 通过标记非终结符号M复写属性的值</p>
<table><tr><td>    </td>
<td class="content">
<P>
标记非终结符号也可用于模拟不是复写规则的语义规则。例如,考虑:
</p>
</td></tr></table>
<table><tr><td>    </td>
<td class="content">
<P>
产生式 语义规则
<br>
S→aAC C.i:=f(A.s) (5.7)
</p>
</td></tr></table>
<table><tr><td>    </td>
<td class="content">
<P>
这里决定C.i的规则不是复写规则,因此C.i的值尚未在栈val中。但问题仍可通过使用标记非终结符号来解决。
</p>
</td></tr></table>
<table><tr><td>    </td>
<td class="content">
<P>
产生式 语义规则
<br>
S→aANC
N.i:=A.s; C.i:=N.s (5.8)
<br>
N→ε N.s:=f(N.i)
</p>
</td></tr></table>
<table><tr><td>    </td>
<td class="content">
<P>
标记非终结符号N通过一个复写规则继承A.s的值。它的综合属性值N.s由f(N.i)给出;然后C.i使用一个复写规则继承这个属性值。当我们对N→ε进行归约时,我们在A.s处得到N.i的值,即在val[top-1]处得到N.i的值。当我们使用产生式S→aANC进行归约时,C.i的值仍然从val[top-1]处得到,因为这个值就是N.s的值。实际上,这时我们不需要C.i;只有在把终结符号串归约为C时才需要用到它,那时,它的值已和N一起安全地存放在栈中了。
</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.6.3.htm'"></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='5.6.3_1.htm'"></img></td>
</tr>
</table>
</BODY>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -