📄 5.9.0e.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.9..htm'" ></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='../c_6/6.0.htm'"></img></td>
</tr>
</table>
<br><br>
<font class="title2"><b>练习</b></font>
<table><tr><td>    </td>
<td class="content">
<a name="5.18"></a>
<hr size=2 align=center color=red><br>
5.18 文法G[P]及其产生式如下: <br>
P→D;E <br>
D→D;D|<b>id</b>:T <br>
T→list of T|<b>char</b>|<b>integer</b>
<br>
E→(L)|Literal|<b>num</b>|<b>id</b>
<br>
L→E,L|E <br>
这个文法产生由字面常量组成的表。符号的解释和文法(5.10)相同,增加类型List,它表示类型为T的元素构成的表。写一个类似5.8.2中图5.33的翻译模式,以确定表达式(E)和(L)的类型(注:表中每个元素的类型是一样的)。
<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.18.htm','','left=50,top=40,toolbar=no,scrollbars=yes,width=600,height=600')"></img>
</td></tr>
</table>
<a name=5.19></a>
<hr size=2 align=center color=red><br>
5.19 修改图5.34的翻译方案,使之能够处理: <br>
a)语句有值。赋值语句的值是赋值号右边的表达式的值。条件语句或当语句的值是语句体的值,语句表的值是表中最后一个语句的值。
<br>
b)布尔表达式。加上逻辑算符and,or和not,还有关系算符的产生式,然后给出适当的翻译规则,计算出这些表达式的类型。
<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.19.htm','','left=50,top=40,toolbar=no,scrollbars=yes,width=600,height=600')"></img>
</td></tr>
</table>
<a name=5.20></a>
<hr size=2 align=center color=red><br>
5.20 假定类型名link和cell如(5.9)中的定义,下面哪些表达式结构等价?哪些名字等价?<br>
(1)Link <br>
(2)pointer(cell) <br>
(3)pointer(Link) <br>
(4)pointer(record(info×integer)×(next×pointer(cell)))
<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.20.htm','','left=50,top=40,toolbar=no,scrollbars=yes,width=600,height=450')"></img>
</td></tr>
</table>
<hr size=2 align=center color=red><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.8.2_3.htm'"></img></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='../c_6/6.0.htm'"></img></td>
</tr>
</table>
</BODY>
<html><script language="JavaScript">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -