/****************************************************************************
* 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