📄 4.10.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='4.9.4.0b.htm'"></img></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='4.10.0b.htm'"></img></td>
</tr>
</table>
<br><br>
<font class="title2"><b>练习</b></font>
<table><tr><td> </td>
<td class="content">
<a name="4.1"></a>
4.1 考虑文法 <br>
R→R'|'R|RR|R*|(R)|a|b </p>
<p>请注意第一个直竖是符号“或”,而不是两个候选式之间的分隔符号。<br>
(1)试说明此文法生成在符号a和b之上的所有正规表达式(除Φ,ε)。 <br>
(2)试说明此文法是二义性的。<br>
(3)试构造一个等价的无二义性文法,此文法给出*、连接和|等运算符号的优先级和结合规则,有关约定见3.4节。<br>
<table align=center width=70%>
<tr><td align=right>
<img src="../images/key.gif" onmouseover="javascript:style.cursor='hand'"
onclick="javascript:window.open('4.10.1.htm','','left=100,top=100,scrollbars=yes,resizable=yes,toolbar=no,width=550,height=500,scrolling=yes')"></img>
</td></tr>
</table>
<a name="4.2"></a>
<hr size=2 align=center color=red><br>
4.2 试分析下面给出的if-then-else语句的文法,它的提出原本是为了矫正dangling-else (悬而未决的-else)文法的二义性:<br>
<table align=center width=450 class="content">
<tr><td>stmt →</td><td>if expr then stmt </td></tr>
<tr><td></td><td>|matched-stmt</td></tr>
<tr><td>matched-stmt→</td><td>if expr then matched-stmt else stmt </td></tr>
<tr><td></td><td>|other </td></tr>
</table>
试说明此文法仍然是二义性的。 <br>
<table align=center width=70%>
<tr><td align=right>
<img src="../images/key.gif" onmouseover="javascript:style.cursor='hand'" onclick="javascript:window.open('4.10.2.htm','','left=100,top=100,scrollbars=yes,resizable=yes,toolbar=no,width=620,height=500,scrolling=yes')"></img>
</td></tr>
</table>
<a name="4.3"></a>
<hr size=2 align=center color=red><br>
4.3 对于给定文法G[bexpr],其产生式如下: <br>
bexpr→bexpr or bterm | bterm <br>
bterm→bterm and bfactor | bfactor <br>
bfactor→not bfactor|(bexpr) |true |false <br>
构造一个递归预测分析程序<br>
<table align=center width=70%>
<tr><td align=right>
<img src="../images/key.gif" onmouseover="javascript:style.cursor='hand'" onclick="javascript:window.open('4.10.3.htm','','left=100,top=100,scrollbars=yes,resizable=yes,toolbar=no,width=500,height=500,scrolling=yes')"></img>
</td></tr>
</table>
<a name="4.4"></a>
<hr size=2 align=center color=red><br>
4.4 已知文法G[S] <br>
S→(L)|a <br>
L→ L,S|S <br>
试为文法G[S]构造一个递归的预测分析器。<br>
<table align=center width=70%>
<tr><td align=right>
<img src="../images/key.gif" onmouseover="javascript:style.cursor='hand'" onclick="javascript:window.open('4.10.4.htm','','left=100,top=100,scrollbars=yes,resizable=yes,toolbar=no,width=500,height=500,scrolling=yes')"></img>
</td></tr>
</table>
<hr size=2 align=center color=red><br>
</td></tr>
</table>
</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='4.9.4.0b.htm'"></img></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='4.10.0b.htm'"></img></td>
</tr>
</table>
</BODY>
</html>
<html><script language="JavaScript">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -