📄 a_5.10.htm
字号:
<html>
<head>
<title>5.10的解答</title>
</head>
<body background="../../images/background.gif" >
<center><font class="title2"><b>练习5.10</b></font></center><br>
<p>解答: </p>
<p>(a) 对于F<sub>1</sub> sub F<sub>2</sub> sub F<sub>3</sub>,其最左推导和分析树如下:</p>
<table align = center border = 0 width = "80%" cellspacing="0" cellpadding="5">
<tr>
<td width = "40%" valign="top"> S => L
<p> => B</p>
<p> => B sub F<sub>3</sub></p>
<p> => B sub F<sub>2</sub> sub
F<sub>3</sub></p>
<p> => F<sub>1</sub> sub
F<sub>2</sub> Sub F<sub>3</sub></p>
</td>
<td width = "60%"><img src="a_5.10.gif" width="169" height="279"></td>
</tr>
</table>
<p> 显然,F<sub>3</sub>.ps:=shrink(F<sub>2</sub>.ps);</p>
<p> F<sub>2</sub>.ps:=shrink(F<sub>1</sub>.ps); </p>
<p> 为此,为B设一个综合属性B.pt,其值等于其下标F的继承属性F.ps。语法制导定义如下: </p>
<table align = center border = 1 width = "80%" cellspacing="0" cellpadding="5">
<tr>
<td width = "32%"><div align = center>产生式</div></td>
<td width = "68%"><div align = center>语义规则</div></td>
</tr>
<tr>
<td >
S -> L
</td>
<td >
L.ps:=10; S.ht:=L.ht;
</td>
</tr>
<tr>
<td >
L -> B
</td>
<td>
B.ps:=L.ps; L.ht:=B.ht;
</td>
</tr>
<tr>
<td>
L -> L<sub>1</sub>B
</td>
<td>
L<sub>1</sub>.ps:=L.ps; B.ps:=L.ps;
<p>L.ht:=max(L<sub>1</sub>.ht,B.ht);
</td>
</tr>
<tr>
<td>
B -> B<sub>1</sub> sub
F
</td>
<td>
B<sub>1</sub>.ps:=B.ps; F.ps:=shrink(B<sub>1</sub>.pt);
<p>B.ht:=disp(B<sub>1</sub>.ht,F.ht);</p>
<p>B.pt:=F.ps;
</td>
</tr>
<tr>
<td>
B -> F
</td>
<td>
F.ps:=B.ps; B.ht:=F.ht;
<p>B.pt:=B.ps;
</td>
</tr>
<tr>
<td>
F -> {L}
</td>
<td>
L.ps:=F.ps; F.ht:=L.ht;
</td>
</tr>
<tr>
<td>
F -> text
</td>
<td>
F.ht:=text.h*F.ps
</td>
</tr>
</table>
<p>(b) 翻译模式如下:</p>
<p>
S -> {L.ps:=10}</p>
<p>
L {S.ht:=L.ht}</p>
<p>
L -> {B.ps:=L.ps}</p>
<p>
B {L.ht:=B.ht}</p>
<p>
L -> {L<sub>1</sub>.ps:=L.ps}</p>
<p>
L<sub>1</sub> {B.ps:=L.ps}</p>
<p>
B {L.ht:=max(L<sub>1</sub>.ht,B.ht)}</p>
<p>
B -> {B<sub>1</sub>.ps:=B.ps}</p>
<p>
B<sub>1</sub></p>
<p>
sub {F.ps:=shrink(B<sub>1</sub>.pt)}</p>
<p>
F {B.ht:=disp(B<sub>1</sub>.ht,F.ht);</p>
<p>
B.pt:=F.ps}</p>
<p>
B -> {F.ps:=B.ps}</p>
<p>
F {B.ht:=F.ht; B.pt:=B.ps}</p>
<p>
F -> {L.ps:=F.ps}</p>
<p>
{L}{F.ht:=L.ht}</p>
<p>
F -> text {F.ht:=text.h*F.ps}
</p>
<p> </p>
</body>
<html><script language="JavaScript">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -