📄 5.9.0.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.8.2_3.htm'"></img></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='5.9.0b.htm'"></img></td>
</tr>
</table>
<br><br>
<font class="title2"><b>练习</b></font>
<table><tr><td>    </td>
<td class="content">
5.1 对于输入的表达式(4*7+1)*2,根据表5.1的语法制导定义建立一棵带注释的分析树。
<table align=center width=70%>
<tr><td align=right>
<img src="../images/key.gif" onmouseover="javascript:style.cursor='hand'" onclick="javascript:window.open('key/a_5.1.htm','','left=50,top=40,toolbar=no,scrollbars=yes,width=600,height=600')"></img>
</td></tr>
</table>
<a name="5.2"></a>
<hr size=2 align=center color=red><br>
5.2 试根据
(a)表5.3中的语法制导定义,和
(b)图5.17的翻译模式,
来建立表达式((a)+(b))的分析树和语法树。
<table align=center width=70%>
<tr><td align=right>
<img src="../images/key.gif" onmouseover="javascript:style.cursor='hand'" onclick="javascript:window.open('key/a_5.2.htm','','left=50,top=40,toolbar=no,scrollbars=yes,width=600,height=600')" width="32" height="32">
</td></tr>
</table>
<hr size=2 align=center color=red><br>
5.3 试给出把中缀表达式转换成没有多余括号的中缀表达式的语法制导定义。例如,由于+和*都是左结合的,((a*(b+c))*(d))可以写成a*(b+c)*d。
<table align=center width=70%>
<tr><td align=right>
<img src="../images/key.gif" onmouseover="javascript:style.cursor='hand'" onclick="javascript:window.open('key/a_5.3.htm','','left=50,top=40,toolbar=no,scrollbars=yes,width=600,height=600')"></img>
</td></tr>
</table>
<hr size=2 align=center color=red><br>
5.4 下面的文法产生的表达式是对整型和实型常数应用算符+形成的。当两个整数相加时,结果仍为整数,否则就是实数。
<br>
E→E+T|T <br>
T→<b>num</b>.<b>num</b>|<b>num</b>
<br>
(a)给出一个语法制导定义以确定每个子表达式的类型。 <br>
(b)扩充(a)中的语法制导定义把表达式翻译成前缀形式,并且决定类型。使用一元算符<b>inttoreal</b>把整型值转换成相等的实型值,以使得前缀形式中的+的两个操作对象是同类型的。
<table align=center width=70%>
<tr><td align=right>
<img src="../images/key.gif" onmouseover="javascript:style.cursor='hand'" onclick="javascript:window.open('key/a_5.4.htm','','left=50,top=40,toolbar=no,scrollbars=yes,width=600,height=600')"></img>
</td></tr>
</table>
<a name=5.5></a>
<hr size=2 align=center color=red><br>
5.5 用S的综合属性val给出在下面的文法中的S产生的二进制数的值(例如,对于输入 101.101,S.val=5.625):
<br>
S→L.L|L <br>
L→LB|B <br>
B→0|1 <br>
(a)试用各有关综合属性决定S.val。 <br>
(b)试用一个语法制导定义来决定S.val,在这个定义中仅有B的综合属性,设为c,它给出由B
生成的位对于最后的数值的分担额。例如,在101.101中的第一位和最后一位对于值5.625的分担额分别为4和0.125。
<table align=center width=70%>
<tr><td align=right>
<img src="../images/key.gif" onmouseover="javascript:style.cursor='hand'" onclick="javascript:window.open('key/a_5.5.htm','','left=50,top=40,toolbar=no,scrollbars=yes,width=700,height=600')"></img>
</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.8.2_3.htm'"></img></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='5.9.0b.htm'"></img></td>
</tr>
</table>
</BODY>
<html><script language="JavaScript">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -