/****************************************************************************
* U N R E G I S T E R E D C O P Y
*
* You are on day 30 of your 30 day trial period.
*
* This file was produced by an UNREGISTERED COPY of Parser Generator. It is
* for evaluation purposes only. If you continue to use Parser Generator 30
* days after installation then you are required to purchase a license. For
* more information see the online help or go to the Bumble-Bee Software
* homepage at:
*
* http://www.bumblebeesoftware.com
*
* This notice must remain present in the file. It cannot be removed.
****************************************************************************/
/****************************************************************************
* homework2.cpp
* C++ source file generated from homework2.y.
*
* Date: 10/22/08
* Time: 21:09:32
*
* AYACC Version: 2.06
****************************************************************************/
#include <yycpars.h>
// namespaces
#ifdef YYSTDCPPLIB
using namespace std;
#endif
#ifdef YYNAMESPACE
using namespace yl;
#endif
#line 1 ".\\homework2.y"
/****************************************************************************
homework2.y
ParserWizard generated YACC file.
Date: 2008年10月22日
****************************************************************************/
#include <ctype.h>
#include <stdio.h>
#include <stack>
#define EOS '\0'
#define BSIZE 128 //缓冲区大小
#define NONE -1
#define IDNUMMAX 100 //可存储变量的最大数目
#define LETNUMMAX 999 //存储变量名字的区域最大值
int tokenval =NULL ; //记号的属性
char yaccbuf[BSIZE] ;
int lastchar=-1; //lexemes中最后引用的位置
int lastentry=0; //symtable中最后引用的位置
struct entry //符号表的表示格式
{
char *lexptr;
int token ;
};
stack <int> idstack; //声明了1个存储int型元素的栈,栈名是idstack
entry symtable[IDNUMMAX];//定义符号表
char lexemes[LETNUMMAX];//定义变量名字的实际存储区域
#line 75 "homework2.cpp"
// repeated because of possible precompiled header
#include <yycpars.h>
// namespaces
#ifdef YYSTDCPPLIB
using namespace std;
#endif
#ifdef YYNAMESPACE
using namespace yl;
#endif
#include ".\homework2.h"
/////////////////////////////////////////////////////////////////////////////
// constructor
YYPARSERNAME::YYPARSERNAME()
{
yytables();
#line 51 ".\\homework2.y"
// place any extra initialisation code here
int lookup(char*s);
int insert(char*s);
void error(char*m);
#line 102 "homework2.cpp"
}
/////////////////////////////////////////////////////////////////////////////
// destructor
YYPARSERNAME::~YYPARSERNAME()
{
// allows virtual functions to be called properly for correct cleanup
yydestroy();
#line 61 ".\\homework2.y"
// place any extra cleanup code here
#line 116 "homework2.cpp"
}
#ifndef YYSTYPE
#define YYSTYPE int
#endif
#ifndef YYSTACK_SIZE
#define YYSTACK_SIZE 100
#endif
#ifndef YYSTACK_MAX
#define YYSTACK_MAX 0
#endif
/****************************************************************************
* N O T E
*
* If the compiler generates a YYPARSERNAME error then you have not declared
* the name of the parser. The easiest way to do this is to use a name
* declaration. This is placed in the declarations section of your YACC
* source file and is introduced with the %name keyword. For instance, the
* following name declaration declares the parser myparser:
*
* %name myparser
*
* For more information see help.
****************************************************************************/
// yyattribute
#ifdef YYDEBUG
void YYFAR* YYPARSERNAME::yyattribute1(int index) const
{
YYSTYPE YYFAR* p = &((YYSTYPE YYFAR*)yyattributestackptr)[yytop + index];
return p;
}
#define yyattribute(index) (*(YYSTYPE YYFAR*)yyattribute1(index))
#else
#define yyattribute(index) (((YYSTYPE YYFAR*)yyattributestackptr)[yytop + (index)])
#endif
void YYPARSERNAME::yystacktoval(int index)
{
yyassert(index >= 0);
*(YYSTYPE YYFAR*)yyvalptr = ((YYSTYPE YYFAR*)yyattributestackptr)[index];
}
void YYPARSERNAME::yyvaltostack(int index)
{
yyassert(index >= 0);
((YYSTYPE YYFAR*)yyattributestackptr)[index] = *(YYSTYPE YYFAR*)yyvalptr;
}
void YYPARSERNAME::yylvaltoval()
{
*(YYSTYPE YYFAR*)yyvalptr = *(YYSTYPE YYFAR*)yylvalptr;
}
void YYPARSERNAME::yyvaltolval()
{
*(YYSTYPE YYFAR*)yylvalptr = *(YYSTYPE YYFAR*)yyvalptr;
}
void YYPARSERNAME::yylvaltostack(int index)
{
yyassert(index >= 0);
((YYSTYPE YYFAR*)yyattributestackptr)[index] = *(YYSTYPE YYFAR*)yylvalptr;
}
void YYFAR* YYPARSERNAME::yynewattribute(int count)
{
yyassert(count >= 0);
return new YYFAR YYSTYPE[count];
}
void YYPARSERNAME::yydeleteattribute(void YYFAR* attribute)
{
delete[] (YYSTYPE YYFAR*)attribute;
}
void YYPARSERNAME::yycopyattribute(void YYFAR* dest, const void YYFAR* src, int count)
{
for (int i = 0; i < count; i++) {
((YYSTYPE YYFAR*)dest)[i] = ((YYSTYPE YYFAR*)src)[i];
}
}
#ifdef YYDEBUG
void YYPARSERNAME::yyinitdebug(void YYFAR** p, int count) const
{
yyassert(p != NULL);
yyassert(count >= 1);
YYSTYPE YYFAR** p1 = (YYSTYPE YYFAR**)p;
for (int i = 0; i < count; i++) {
p1[i] = &((YYSTYPE YYFAR*)yyattributestackptr)[yytop + i - (count - 1)];
}
}
#endif
void YYPARSERNAME::yyaction(int action)
{
switch (action) {
case 0:
{
#ifdef YYDEBUG
YYSTYPE YYFAR* yya[4];
yyinitdebug((void YYFAR**)yya, 4);
#endif
{
#line 98 ".\\homework2.y"
if(yyattribute(2 - 3)<=-6e+066){cout<<endl;}else{cout<<yyattribute(2 - 3)<<endl;}
#line 226 "homework2.cpp"
}
}
break;
case 1:
{
#ifdef YYDEBUG
YYSTYPE YYFAR* yya[4];
yyinitdebug((void YYFAR**)yya, 4);
#endif
{
#line 99 ".\\homework2.y"
;
#line 239 "homework2.cpp"
}
}
break;
case 2:
{
#ifdef YYDEBUG
YYSTYPE YYFAR* yya[4];
yyinitdebug((void YYFAR**)yya, 4);
#endif
{
#line 104 ".\\homework2.y"
(*(YYSTYPE YYFAR*)yyvalptr) = yyattribute(1 - 3) + yyattribute(3 - 3);
#line 252 "homework2.cpp"
}
}
break;
case 3:
{
#ifdef YYDEBUG
YYSTYPE YYFAR* yya[4];
yyinitdebug((void YYFAR**)yya, 4);
#endif
{
#line 105 ".\\homework2.y"
(*(YYSTYPE YYFAR*)yyvalptr) = yyattribute(1 - 3) - yyattribute(3 - 3);
#line 265 "homework2.cpp"
}
}
break;
case 4:
{
#ifdef YYDEBUG
YYSTYPE YYFAR* yya[4];
yyinitdebug((void YYFAR**)yya, 4);
#endif
{
#line 106 ".\\homework2.y"
(*(YYSTYPE YYFAR*)yyvalptr) = yyattribute(1 - 3) * yyattribute(3 - 3);
#line 278 "homework2.cpp"
}
}
break;
case 5:
{
#ifdef YYDEBUG
YYSTYPE YYFAR* yya[4];
yyinitdebug((void YYFAR**)yya, 4);
#endif
{
#line 107 ".\\homework2.y"
(*(YYSTYPE YYFAR*)yyvalptr) = yyattribute(1 - 3) / yyattribute(3 - 3);
#line 291 "homework2.cpp"
}
}
break;
case 6:
{
#ifdef YYDEBUG
YYSTYPE YYFAR* yya[4];
yyinitdebug((void YYFAR**)yya, 4);
#endif
{
#line 108 ".\\homework2.y"
(*(YYSTYPE YYFAR*)yyvalptr) = yyattribute(2 - 3);
#line 304 "homework2.cpp"
}
}
break;
case 7:
{
#ifdef YYDEBUG
YYSTYPE YYFAR* yya[3];
yyinitdebug((void YYFAR**)yya, 3);
#endif
{
#line 109 ".\\homework2.y"
(*(YYSTYPE YYFAR*)yyvalptr) = -yyattribute(2 - 2);
#line 317 "homework2.cpp"
}
}
break;
case 8:
{
#ifdef YYDEBUG
YYSTYPE YYFAR* yya[4];
yyinitdebug((void YYFAR**)yya, 4);
#endif
{
#line 110 ".\\homework2.y"
(*(YYSTYPE YYFAR*)yyvalptr) = yyattribute(3 - 3); tokenval=idstack.top(); idstack.pop(); symtable[tokenval].token = yyattribute(3 - 3);
#line 330 "homework2.cpp"
}
}
break;
case 9:
{
#ifdef YYDEBUG
YYSTYPE YYFAR* yya[2];
yyinitdebug((void YYFAR**)yya, 2);
#endif
{
#line 111 ".\\homework2.y"
(*(YYSTYPE YYFAR*)yyvalptr) = tokenv
没有合适的资源?快使用搜索试试~ 我知道了~
编译原理表达式运算-实现四则运算,赋值预算,变量赋值
共19个文件
obj:2个
pdb:2个
pgw:1个
5星 · 超过95%的资源 需积分: 34 33 下载量 80 浏览量
2008-12-11
17:39:58
上传
评论 2
收藏 990KB RAR 举报
温馨提示
Yacc程序编写文法 生成C程序能是实现表达式运算 赋值运算 变量赋值后参与运算等
资源推荐
资源详情
资源评论
收起资源包目录
-表达式运算.rar (19个子文件)
编译第二次作业-表达式运算
编译homework2.ncb 41KB
编译homework2.dsw 534B
homework2.h 2KB
homework2.v 5KB
Debug
编译homework2.ilk 808KB
vc60.pdb 116KB
vc60.idb 97KB
homework2.obj 211KB
编译homework2.exe 596KB
编译homework2.pch 1.93MB
编译homework2.pdb 1.13MB
123.obj 211KB
编译homework2.opt 48KB
编译homework2.dsp 4KB
homework2.pgw 368B
编译homework2.plg 260B
homework2.cpp 21KB
homework2.y 5KB
homework2.pgp 733B
共 19 条
- 1
资源评论
- seek_facts2013-07-03测试了可以用,不错
Jackshen1986
- 粉丝: 8
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功