📄 4.9.2.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.1.1b.htm'"></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='4.9.2.0b.htm'"></img></td>
</tr>
</table>
<br><br>
<font class="title2"><b>4.9.2 用Yacc处理二义文法
</b></font>
<table><tr><td> </td>
<td class="content">
<p>现在我们修改这个Yacc说明,使台式计算器更加有用。首先,我们让台式计算器计算表达式序列,每行一个,还允许表达式之间有空白行。为做到这样,改变第一条规则为
<table align=center width=550 class="content">
<tr><td>lines :</td><td>lines expr '\n’ { printf (”%g\n”,$2) ; </td></tr>
<tr><td></td><td>| lines'\n’</td></tr>
<tr><td></td><td>|</td></tr>
<tr><td></td><td>;</td></tr>
</table>
在Yacc中,第三行的空选择表示ε。
<p>其次,扩大表达式的类,使之包含多个数字组成的数,包括算符+,- (一元和二元),* 和/ 。说明这类表达式的最简单方法是用二义文法 <br>
E→E+E|E-E|E*E|E/E|(E)|-E|number <br>
最终的Yacc源程序见下页的图4.30。
</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='4.9.1.1b.htm'"></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='4.9.2.0b.htm'"></img></td>
</tr>
</table>
</BODY>
<html><script language="JavaScript">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -