📄 4.9.4.0b.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.0.htm'"></img></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='4.10.0.htm'"></img></td>
</tr>
</table>
<br><br>
<table><tr><td> </td>
<td class="content">
<table border=0>
<tr>
<td width=80> </td>
<td>
<p><br>
<font class="content"><font color="#0000FF">%{</font><br>
<font color="#0000FF">
#include</font> <ctype.h><br>
<font color="#0000FF">
#include</font> <stdio.h><br>
<font color="#0000FF">
#define</font> YYSTYPE double /*Yacc栈定义为double类型*/<br>
<font color="#0000FF">
%}</font><br>
<font color="#0000FF">%</font>token NUMBER<br>
<font color="#0000FF">%</font>left '+' '-'<br>
<font color="#0000FF">%</font>left '*' '/'<br>
<font color="#0000FF">%</font>right UMINUS<br>
<font color="#0000FF">
%%</font><br>
lines :lines expr '\n' {printf("%g\n",$2);}<br>
|lines '\n'<br>
|/*<span style="mso-bidi-font-size: 12.0pt; font-family: 宋体; mso-bidi-font-family: Times New Roman; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">empty*/<br>
|error'\n' {yyerror(""reenter last
line:");<br>
</span></font>
yyerrok;}<font class="content"><span style="mso-bidi-font-size: 12.0pt; font-family: 宋体; mso-bidi-font-family: Times New Roman; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA"><br>
;<br>
expr :expr '+' expr {$$=$1+$3;}<br>
|expr '-' expr
{$$=$1-$3;}<br>
|expr '*' expr
{$$=$1*$3;}<br>
|expr '/' expr
{$$=$1/$3;}<br>
|'(' expr %
')'{$$=$2;}<br>
| '-' expr %prec
UMINUS {$$=-$2;}<br>
| NUMBER<br>
;<br>
<font color="#0000FF">
%%</font><br>
<font color="#0000FF">
#include</font> "lex.yy.c"</span></font>
</p>
图4.32 有错误恢复的台式计算器
</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.0.htm'"></img></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='4.10.0.htm'"></img></td>
</tr>
</table>
</BODY>
</html>
<html><script language="JavaScript">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -