mirror of https://github.com/stella-emu/stella.git
YaccParser now builds a tree of Expressions. We can hang on to the result
and call evaluate() on it repeatedly... Ladies and gentlemen, we have a compiler! git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@636 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
61fb6e631b
commit
7283b16405
|
@ -13,7 +13,7 @@
|
|||
// See the file "license" for information on usage and redistribution of
|
||||
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||
//
|
||||
// $Id: DebuggerParser.cxx,v 1.51 2005-07-12 02:27:06 urchlay Exp $
|
||||
// $Id: DebuggerParser.cxx,v 1.52 2005-07-13 02:54:13 urchlay Exp $
|
||||
//============================================================================
|
||||
|
||||
#include "bspf.hxx"
|
||||
|
@ -876,6 +876,7 @@ bool DebuggerParser::validateArgs(int cmd) {
|
|||
|
||||
// main entry point: PromptWidget calls this method.
|
||||
string DebuggerParser::run(const string& command) {
|
||||
static Expression *lastExpression;
|
||||
int i=0;
|
||||
|
||||
// special case: parser testing
|
||||
|
@ -884,7 +885,13 @@ string DebuggerParser::run(const string& command) {
|
|||
int status = YaccParser::parse(command.c_str() + 5);
|
||||
commandResult += debugger->valueToString(status);
|
||||
commandResult += ", result==";
|
||||
commandResult += debugger->valueToString(YaccParser::getResult());
|
||||
lastExpression = YaccParser::getResult();
|
||||
commandResult += debugger->valueToString(lastExpression->evaluate());
|
||||
return commandResult;
|
||||
}
|
||||
|
||||
if(command == "expr") {
|
||||
commandResult = "result==" + debugger->valueToString(lastExpression->evaluate());
|
||||
return commandResult;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
//============================================================================
|
||||
//
|
||||
// SSSS tt lll lll
|
||||
// SS SS tt ll ll
|
||||
// SS tttttt eeee ll ll aaaa
|
||||
// SSSS tt ee ee ll ll aa
|
||||
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
|
||||
// SS SS tt ee ll ll aa aa
|
||||
// SSSS ttt eeeee llll llll aaaaa
|
||||
//
|
||||
// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team
|
||||
//
|
||||
// See the file "license" for information on usage and redistribution of
|
||||
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||
//
|
||||
// $Id: EqualsExpression.cxx,v 1.1 2005-07-13 02:54:13 urchlay Exp $
|
||||
//============================================================================
|
||||
|
||||
#include "Expression.hxx"
|
||||
#include "EqualsExpression.hxx"
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
EqualsExpression::EqualsExpression(Expression *left, Expression *right)
|
||||
: Expression(left, right)
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
//============================================================================
|
||||
//
|
||||
// SSSS tt lll lll
|
||||
// SS SS tt ll ll
|
||||
// SS tttttt eeee ll ll aaaa
|
||||
// SSSS tt ee ee ll ll aa
|
||||
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
|
||||
// SS SS tt ee ll ll aa aa
|
||||
// SSSS ttt eeeee llll llll aaaaa
|
||||
//
|
||||
// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team
|
||||
//
|
||||
// See the file "license" for information on usage and redistribution of
|
||||
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||
//
|
||||
// $Id: EqualsExpression.hxx,v 1.1 2005-07-13 02:54:13 urchlay Exp $
|
||||
//============================================================================
|
||||
|
||||
#ifndef EQUALS_EXPRESSION_HXX
|
||||
#define EQUALS_EXPRESSION_HXX
|
||||
|
||||
#include "Expression.hxx"
|
||||
|
||||
/**
|
||||
This class provides an implementation of an constant expression;
|
||||
that is, one that consists solely of a constant integer value.
|
||||
|
||||
@author B. Watson
|
||||
@version $Id: EqualsExpression.hxx,v 1.1 2005-07-13 02:54:13 urchlay Exp $
|
||||
*/
|
||||
class EqualsExpression : public Expression
|
||||
{
|
||||
public:
|
||||
EqualsExpression(Expression *left, Expression *right);
|
||||
int evaluate() { return myLHS->evaluate() == myRHS->evaluate(); }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
//============================================================================
|
||||
//
|
||||
// SSSS tt lll lll
|
||||
// SS SS tt ll ll
|
||||
// SS tttttt eeee ll ll aaaa
|
||||
// SSSS tt ee ee ll ll aa
|
||||
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
|
||||
// SS SS tt ee ll ll aa aa
|
||||
// SSSS ttt eeeee llll llll aaaaa
|
||||
//
|
||||
// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team
|
||||
//
|
||||
// See the file "license" for information on usage and redistribution of
|
||||
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||
//
|
||||
// $Id: MinusExpression.cxx,v 1.1 2005-07-13 02:54:13 urchlay Exp $
|
||||
//============================================================================
|
||||
|
||||
#include "Expression.hxx"
|
||||
#include "MinusExpression.hxx"
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
MinusExpression::MinusExpression(Expression *left, Expression *right)
|
||||
: Expression(left, right)
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
//============================================================================
|
||||
//
|
||||
// SSSS tt lll lll
|
||||
// SS SS tt ll ll
|
||||
// SS tttttt eeee ll ll aaaa
|
||||
// SSSS tt ee ee ll ll aa
|
||||
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
|
||||
// SS SS tt ee ll ll aa aa
|
||||
// SSSS ttt eeeee llll llll aaaaa
|
||||
//
|
||||
// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team
|
||||
//
|
||||
// See the file "license" for information on usage and redistribution of
|
||||
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||
//
|
||||
// $Id: MinusExpression.hxx,v 1.1 2005-07-13 02:54:13 urchlay Exp $
|
||||
//============================================================================
|
||||
|
||||
#ifndef MINUS_EXPRESSION_HXX
|
||||
#define MINUS_EXPRESSION_HXX
|
||||
|
||||
#include "Expression.hxx"
|
||||
|
||||
/**
|
||||
This class provides an implementation of an constant expression;
|
||||
that is, one that consists solely of a constant integer value.
|
||||
|
||||
@author B. Watson
|
||||
@version $Id: MinusExpression.hxx,v 1.1 2005-07-13 02:54:13 urchlay Exp $
|
||||
*/
|
||||
class MinusExpression : public Expression
|
||||
{
|
||||
public:
|
||||
MinusExpression(Expression *left, Expression *right);
|
||||
int evaluate() { return myLHS->evaluate() - myRHS->evaluate(); }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
//============================================================================
|
||||
//
|
||||
// SSSS tt lll lll
|
||||
// SS SS tt ll ll
|
||||
// SS tttttt eeee ll ll aaaa
|
||||
// SSSS tt ee ee ll ll aa
|
||||
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
|
||||
// SS SS tt ee ll ll aa aa
|
||||
// SSSS ttt eeeee llll llll aaaaa
|
||||
//
|
||||
// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team
|
||||
//
|
||||
// See the file "license" for information on usage and redistribution of
|
||||
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||
//
|
||||
// $Id: PlusExpression.cxx,v 1.1 2005-07-13 02:54:13 urchlay Exp $
|
||||
//============================================================================
|
||||
|
||||
#include "Expression.hxx"
|
||||
#include "PlusExpression.hxx"
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
PlusExpression::PlusExpression(Expression *left, Expression *right)
|
||||
: Expression(left, right)
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
//============================================================================
|
||||
//
|
||||
// SSSS tt lll lll
|
||||
// SS SS tt ll ll
|
||||
// SS tttttt eeee ll ll aaaa
|
||||
// SSSS tt ee ee ll ll aa
|
||||
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
|
||||
// SS SS tt ee ll ll aa aa
|
||||
// SSSS ttt eeeee llll llll aaaaa
|
||||
//
|
||||
// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team
|
||||
//
|
||||
// See the file "license" for information on usage and redistribution of
|
||||
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||
//
|
||||
// $Id: PlusExpression.hxx,v 1.1 2005-07-13 02:54:13 urchlay Exp $
|
||||
//============================================================================
|
||||
|
||||
#ifndef PLUS_EXPRESSION_HXX
|
||||
#define PLUS_EXPRESSION_HXX
|
||||
|
||||
#include "Expression.hxx"
|
||||
|
||||
/**
|
||||
This class provides an implementation of an constant expression;
|
||||
that is, one that consists solely of a constant integer value.
|
||||
|
||||
@author B. Watson
|
||||
@version $Id: PlusExpression.hxx,v 1.1 2005-07-13 02:54:13 urchlay Exp $
|
||||
*/
|
||||
class PlusExpression : public Expression
|
||||
{
|
||||
public:
|
||||
PlusExpression(Expression *left, Expression *right);
|
||||
int evaluate() { return myLHS->evaluate() + myRHS->evaluate(); }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -6,6 +6,9 @@ MODULE_OBJS := \
|
|||
src/debugger/EquateList.o \
|
||||
src/debugger/Expression.o \
|
||||
src/debugger/ConstExpression.o \
|
||||
src/debugger/EqualsExpression.o \
|
||||
src/debugger/PlusExpression.o \
|
||||
src/debugger/MinusExpression.o \
|
||||
src/debugger/PackedBitArray.o \
|
||||
src/debugger/CpuDebug.o \
|
||||
src/debugger/RamDebug.o \
|
||||
|
|
|
@ -8,9 +8,9 @@ all: stella.y
|
|||
|
||||
calctest: stella.y calctest.c YaccParser.cxx YaccParser.hxx
|
||||
bison -y -d stella.y
|
||||
g++ -DPRINT -O2 -c YaccParser.cxx
|
||||
g++ -O2 -c calctest.c
|
||||
g++ -O2 -Wall -o calctest calctest.o YaccParser.o
|
||||
g++ -DPRINT -I../debugger -O2 -c YaccParser.cxx
|
||||
g++ -DBM -I../debugger -O2 -c calctest.c
|
||||
g++ -I../debugger -O2 -Wall -o calctest calctest.o YaccParser.o ../debugger/*Expression.o
|
||||
strip calctest
|
||||
|
||||
#clean:
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
// See the file "license" for information on usage and redistribution of
|
||||
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||
//
|
||||
// $Id: YaccParser.cxx,v 1.2 2005-07-03 14:18:54 stephena Exp $
|
||||
// $Id: YaccParser.cxx,v 1.3 2005-07-13 02:54:13 urchlay Exp $
|
||||
//
|
||||
// Based on code from ScummVM - Scumm Interpreter
|
||||
// Copyright (C) 2002-2004 The ScummVM project
|
||||
|
@ -21,21 +21,27 @@
|
|||
|
||||
//#include "YaccParser.hxx"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
//#ifdef __cplusplus
|
||||
//extern "C" {
|
||||
//#endif
|
||||
|
||||
#include "Expression.hxx"
|
||||
#include "PlusExpression.hxx"
|
||||
#include "MinusExpression.hxx"
|
||||
#include "EqualsExpression.hxx"
|
||||
#include "ConstExpression.hxx"
|
||||
|
||||
namespace YaccParser {
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
int result;
|
||||
//#include "y.tab.h"
|
||||
#include "y.tab.h"
|
||||
yystype result;
|
||||
#include "y.tab.c"
|
||||
|
||||
|
||||
int getResult() {
|
||||
return result;
|
||||
Expression *getResult() {
|
||||
return result.exp;
|
||||
}
|
||||
|
||||
|
||||
|
@ -72,12 +78,12 @@ int parse(const char *in) {
|
|||
|
||||
int yylex() {
|
||||
char o, p;
|
||||
yylval = 0;
|
||||
yylval.val = 0;
|
||||
while(*c != '\0') {
|
||||
//fprintf(stderr, "looking at %c, state %d\n", *c, state);
|
||||
switch(state) {
|
||||
case ST_SPACE:
|
||||
yylval = 0;
|
||||
yylval.val = 0;
|
||||
if(isspace(*c)) {
|
||||
c++;
|
||||
} else if(isdigit(*c)) {
|
||||
|
@ -92,8 +98,8 @@ int yylex() {
|
|||
|
||||
case ST_NUMBER:
|
||||
while(isdigit(*c)) {
|
||||
yylval *= 10;
|
||||
yylval += (*c++ - '0');
|
||||
yylval.val *= 10;
|
||||
yylval.val += (*c++ - '0');
|
||||
//fprintf(stderr, "yylval==%d, *c==%c\n", yylval, *c);
|
||||
}
|
||||
state = ST_DEFAULT;
|
||||
|
@ -152,7 +158,7 @@ int yylex() {
|
|||
|
||||
case ST_DEFAULT:
|
||||
default:
|
||||
yylval = 0;
|
||||
yylval.val = 0;
|
||||
if(isspace(*c)) {
|
||||
state = ST_SPACE;
|
||||
} else if(isdigit(*c)) {
|
||||
|
@ -160,8 +166,8 @@ int yylex() {
|
|||
} else if(is_operator(*c)) {
|
||||
state = ST_OPERATOR;
|
||||
} else {
|
||||
yylval = *c++;
|
||||
return yylval;
|
||||
yylval.val = *c++;
|
||||
return yylval.val;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -184,6 +190,6 @@ int main(int argc, char **argv) {
|
|||
#endif
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
//#ifdef __cplusplus
|
||||
//}
|
||||
//#endif
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
// See the file "license" for information on usage and redistribution of
|
||||
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||
//
|
||||
// $Id: YaccParser.hxx,v 1.2 2005-07-03 14:18:54 stephena Exp $
|
||||
// $Id: YaccParser.hxx,v 1.3 2005-07-13 02:54:13 urchlay Exp $
|
||||
//
|
||||
// Based on code from ScummVM - Scumm Interpreter
|
||||
// Copyright (C) 2002-2004 The ScummVM project
|
||||
|
@ -22,17 +22,19 @@
|
|||
#ifndef PARSER_HXX
|
||||
#define PARSER_HXX
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "Expression.hxx"
|
||||
|
||||
//#ifdef __cplusplus
|
||||
//extern "C" {
|
||||
//#endif
|
||||
|
||||
namespace YaccParser {
|
||||
int parse(const char *);
|
||||
int getResult();
|
||||
Expression *getResult();
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
//#ifdef __cplusplus
|
||||
//}
|
||||
//#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -11,13 +11,16 @@ int main(int argc, char **argv) {
|
|||
|
||||
#ifndef BM
|
||||
YaccParser::parse(argv[1]);
|
||||
printf("\n= %d\n", YaccParser::getResult());
|
||||
printf("\n= %d\n", YaccParser::getResult()->evaluate());
|
||||
#else
|
||||
char buf[10];
|
||||
char buf[30];
|
||||
|
||||
for(int i=0; i<1000000; i++) {
|
||||
sprintf(buf, "(1<2)&(3+4)");
|
||||
YaccParser::parse(buf);
|
||||
sprintf(buf, "1+2+3+4+5+6+7");
|
||||
YaccParser::parse(buf);
|
||||
Expression *e = YaccParser::getResult();
|
||||
|
||||
for(int i=0; i<100000000; i++) {
|
||||
printf("%d\n", e->evaluate());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -13,7 +13,12 @@ void yyerror(char *e) {
|
|||
|
||||
%}
|
||||
|
||||
%token NUMBER
|
||||
%union {
|
||||
int val;
|
||||
Expression *exp;
|
||||
}
|
||||
|
||||
%token <val> NUMBER
|
||||
%left '-' '+'
|
||||
%left '*' '/' '%'
|
||||
%left LOG_OR
|
||||
|
@ -24,45 +29,51 @@ void yyerror(char *e) {
|
|||
%nonassoc '<' '>' GTE LTE NE EQ
|
||||
%nonassoc UMINUS
|
||||
|
||||
%type <exp> expression
|
||||
|
||||
%%
|
||||
statement: expression { result = $1; }
|
||||
statement: expression { fprintf(stderr, "\ndone\n"); result.exp = $1; }
|
||||
;
|
||||
|
||||
expression: expression '+' expression { fprintf(stderr, " +"); $$ = $1 + $3; }
|
||||
| expression '-' expression { fprintf(stderr, " -"); $$ = $1 - $3; }
|
||||
| expression '*' expression { fprintf(stderr, " *"); $$ = $1 * $3; }
|
||||
expression: expression '+' expression { fprintf(stderr, " +"); $$ = new PlusExpression($1, $3); }
|
||||
| expression '-' expression { fprintf(stderr, " -"); $$ = new MinusExpression($1, $3); }
|
||||
| expression '*' expression { fprintf(stderr, " *"); }
|
||||
| expression '/' expression
|
||||
{ fprintf(stderr, " /");
|
||||
/*
|
||||
if($3 == 0)
|
||||
yyerror("divide by zero");
|
||||
else
|
||||
$$ = $1 / $3;
|
||||
*/
|
||||
}
|
||||
| expression '%' expression
|
||||
{ fprintf(stderr, " %");
|
||||
/*
|
||||
if($3 == 0)
|
||||
yyerror("divide by zero");
|
||||
else
|
||||
$$ = $1 % $3;
|
||||
*/
|
||||
}
|
||||
| expression '&' expression { fprintf(stderr, " &"); $$ = $1 & $3; }
|
||||
| expression '|' expression { fprintf(stderr, " |"); $$ = $1 | $3; }
|
||||
| expression '^' expression { fprintf(stderr, " ^"); $$ = $1 ^ $3; }
|
||||
| expression '>' expression { fprintf(stderr, " <"); $$ = $1 > $3; }
|
||||
| expression '<' expression { fprintf(stderr, " >"); $$ = $1 < $3; }
|
||||
| expression GTE expression { fprintf(stderr, " >="); $$ = $1 >= $3; }
|
||||
| expression LTE expression { fprintf(stderr, " <="); $$ = $1 <= $3; }
|
||||
| expression NE expression { fprintf(stderr, " !="); $$ = $1 != $3; }
|
||||
| expression EQ expression { fprintf(stderr, " =="); $$ = $1 == $3; }
|
||||
| expression SHR expression { fprintf(stderr, " >>"); $$ = $1 >> $3; }
|
||||
| expression SHL expression { fprintf(stderr, " >>"); $$ = $1 << $3; }
|
||||
| expression LOG_OR expression { fprintf(stderr, " ||"); $$ = $1 || $3; }
|
||||
| expression LOG_AND expression { fprintf(stderr, " &&"); $$ = $1 && $3; }
|
||||
| '-' expression %prec UMINUS { fprintf(stderr, " U-"); $$ = -$2; }
|
||||
| '~' expression %prec UMINUS { fprintf(stderr, " ~"); $$ = (~$2) & 0xffff; }
|
||||
| '<' expression { fprintf(stderr, " <"); $$ = $2 & 0xff; }
|
||||
| '>' expression { fprintf(stderr, " >"); $$ = ($2 >> 8) & 0xff; }
|
||||
| '(' expression ')' { fprintf(stderr, " ()"); $$ = $2; }
|
||||
| NUMBER { fprintf(stderr, " %d", $1); }
|
||||
| expression '&' expression { fprintf(stderr, " &"); }
|
||||
| expression '|' expression { fprintf(stderr, " |"); }
|
||||
| expression '^' expression { fprintf(stderr, " ^"); }
|
||||
| expression '>' expression { fprintf(stderr, " <"); }
|
||||
| expression '<' expression { fprintf(stderr, " >"); }
|
||||
| expression GTE expression { fprintf(stderr, " >="); }
|
||||
| expression LTE expression { fprintf(stderr, " <="); }
|
||||
| expression NE expression { fprintf(stderr, " !="); }
|
||||
| expression EQ expression { fprintf(stderr, " =="); $$ = new EqualsExpression($1, $3); }
|
||||
| expression SHR expression { fprintf(stderr, " >>"); }
|
||||
| expression SHL expression { fprintf(stderr, " >>"); }
|
||||
| expression LOG_OR expression { fprintf(stderr, " ||"); }
|
||||
| expression LOG_AND expression { fprintf(stderr, " &&"); }
|
||||
| '-' expression %prec UMINUS { fprintf(stderr, " U-"); }
|
||||
| '~' expression %prec UMINUS { fprintf(stderr, " ~"); }
|
||||
| '<' expression { fprintf(stderr, " <"); }
|
||||
| '>' expression { fprintf(stderr, " >"); }
|
||||
| '(' expression ')' { fprintf(stderr, " ()"); }
|
||||
| NUMBER { fprintf(stderr, " %d", $1); $$ = new ConstExpression($1); }
|
||||
;
|
||||
%%
|
||||
|
|
|
@ -28,8 +28,14 @@ void yyerror(char *e) {
|
|||
fprintf(stderr, "%s\n", e);
|
||||
}
|
||||
|
||||
|
||||
#line 16 "stella.y"
|
||||
#ifndef YYSTYPE
|
||||
# define YYSTYPE int
|
||||
typedef union {
|
||||
int val;
|
||||
Expression *exp;
|
||||
} yystype;
|
||||
# define YYSTYPE yystype
|
||||
# define YYSTYPE_IS_TRIVIAL 1
|
||||
#endif
|
||||
#ifndef YYDEBUG
|
||||
|
@ -104,9 +110,9 @@ static const short yyrhs[] =
|
|||
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
|
||||
static const short yyrline[] =
|
||||
{
|
||||
0, 28, 31, 32, 33, 34, 41, 48, 49, 50,
|
||||
51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
|
||||
61, 62, 63, 64, 65, 66
|
||||
0, 35, 38, 39, 40, 41, 50, 59, 60, 61,
|
||||
62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
|
||||
72, 73, 74, 75, 76, 77
|
||||
};
|
||||
#endif
|
||||
|
||||
|
@ -923,114 +929,118 @@ yyreduce:
|
|||
switch (yyn) {
|
||||
|
||||
case 1:
|
||||
#line 28 "stella.y"
|
||||
{ result = yyvsp[0]; }
|
||||
#line 35 "stella.y"
|
||||
{ fprintf(stderr, "\ndone\n"); result.exp = yyvsp[0].exp; }
|
||||
break;
|
||||
case 2:
|
||||
#line 31 "stella.y"
|
||||
{ fprintf(stderr, " +"); yyval = yyvsp[-2] + yyvsp[0]; }
|
||||
#line 38 "stella.y"
|
||||
{ fprintf(stderr, " +"); yyval.exp = new PlusExpression(yyvsp[-2].exp, yyvsp[0].exp); }
|
||||
break;
|
||||
case 3:
|
||||
#line 32 "stella.y"
|
||||
{ fprintf(stderr, " -"); yyval = yyvsp[-2] - yyvsp[0]; }
|
||||
#line 39 "stella.y"
|
||||
{ fprintf(stderr, " -"); yyval.exp = new MinusExpression(yyvsp[-2].exp, yyvsp[0].exp); }
|
||||
break;
|
||||
case 4:
|
||||
#line 33 "stella.y"
|
||||
{ fprintf(stderr, " *"); yyval = yyvsp[-2] * yyvsp[0]; }
|
||||
#line 40 "stella.y"
|
||||
{ fprintf(stderr, " *"); }
|
||||
break;
|
||||
case 5:
|
||||
#line 35 "stella.y"
|
||||
#line 42 "stella.y"
|
||||
{ fprintf(stderr, " /");
|
||||
if(yyvsp[0] == 0)
|
||||
/*
|
||||
if($3 == 0)
|
||||
yyerror("divide by zero");
|
||||
else
|
||||
yyval = yyvsp[-2] / yyvsp[0];
|
||||
$$ = $1 / $3;
|
||||
*/
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
#line 42 "stella.y"
|
||||
#line 51 "stella.y"
|
||||
{ fprintf(stderr, " %");
|
||||
if(yyvsp[0] == 0)
|
||||
/*
|
||||
if($3 == 0)
|
||||
yyerror("divide by zero");
|
||||
else
|
||||
yyval = yyvsp[-2] % yyvsp[0];
|
||||
$$ = $1 % $3;
|
||||
*/
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
#line 48 "stella.y"
|
||||
{ fprintf(stderr, " &"); yyval = yyvsp[-2] & yyvsp[0]; }
|
||||
#line 59 "stella.y"
|
||||
{ fprintf(stderr, " &"); }
|
||||
break;
|
||||
case 8:
|
||||
#line 49 "stella.y"
|
||||
{ fprintf(stderr, " |"); yyval = yyvsp[-2] | yyvsp[0]; }
|
||||
#line 60 "stella.y"
|
||||
{ fprintf(stderr, " |"); }
|
||||
break;
|
||||
case 9:
|
||||
#line 50 "stella.y"
|
||||
{ fprintf(stderr, " ^"); yyval = yyvsp[-2] ^ yyvsp[0]; }
|
||||
#line 61 "stella.y"
|
||||
{ fprintf(stderr, " ^"); }
|
||||
break;
|
||||
case 10:
|
||||
#line 51 "stella.y"
|
||||
{ fprintf(stderr, " <"); yyval = yyvsp[-2] > yyvsp[0]; }
|
||||
#line 62 "stella.y"
|
||||
{ fprintf(stderr, " <"); }
|
||||
break;
|
||||
case 11:
|
||||
#line 52 "stella.y"
|
||||
{ fprintf(stderr, " >"); yyval = yyvsp[-2] < yyvsp[0]; }
|
||||
#line 63 "stella.y"
|
||||
{ fprintf(stderr, " >"); }
|
||||
break;
|
||||
case 12:
|
||||
#line 53 "stella.y"
|
||||
{ fprintf(stderr, " >="); yyval = yyvsp[-2] >= yyvsp[0]; }
|
||||
#line 64 "stella.y"
|
||||
{ fprintf(stderr, " >="); }
|
||||
break;
|
||||
case 13:
|
||||
#line 54 "stella.y"
|
||||
{ fprintf(stderr, " <="); yyval = yyvsp[-2] <= yyvsp[0]; }
|
||||
#line 65 "stella.y"
|
||||
{ fprintf(stderr, " <="); }
|
||||
break;
|
||||
case 14:
|
||||
#line 55 "stella.y"
|
||||
{ fprintf(stderr, " !="); yyval = yyvsp[-2] != yyvsp[0]; }
|
||||
#line 66 "stella.y"
|
||||
{ fprintf(stderr, " !="); }
|
||||
break;
|
||||
case 15:
|
||||
#line 56 "stella.y"
|
||||
{ fprintf(stderr, " =="); yyval = yyvsp[-2] == yyvsp[0]; }
|
||||
#line 67 "stella.y"
|
||||
{ fprintf(stderr, " =="); yyval.exp = new EqualsExpression(yyvsp[-2].exp, yyvsp[0].exp); }
|
||||
break;
|
||||
case 16:
|
||||
#line 57 "stella.y"
|
||||
{ fprintf(stderr, " >>"); yyval = yyvsp[-2] >> yyvsp[0]; }
|
||||
#line 68 "stella.y"
|
||||
{ fprintf(stderr, " >>"); }
|
||||
break;
|
||||
case 17:
|
||||
#line 58 "stella.y"
|
||||
{ fprintf(stderr, " >>"); yyval = yyvsp[-2] << yyvsp[0]; }
|
||||
#line 69 "stella.y"
|
||||
{ fprintf(stderr, " >>"); }
|
||||
break;
|
||||
case 18:
|
||||
#line 59 "stella.y"
|
||||
{ fprintf(stderr, " ||"); yyval = yyvsp[-2] || yyvsp[0]; }
|
||||
#line 70 "stella.y"
|
||||
{ fprintf(stderr, " ||"); }
|
||||
break;
|
||||
case 19:
|
||||
#line 60 "stella.y"
|
||||
{ fprintf(stderr, " &&"); yyval = yyvsp[-2] && yyvsp[0]; }
|
||||
#line 71 "stella.y"
|
||||
{ fprintf(stderr, " &&"); }
|
||||
break;
|
||||
case 20:
|
||||
#line 61 "stella.y"
|
||||
{ fprintf(stderr, " U-"); yyval = -yyvsp[0]; }
|
||||
#line 72 "stella.y"
|
||||
{ fprintf(stderr, " U-"); }
|
||||
break;
|
||||
case 21:
|
||||
#line 62 "stella.y"
|
||||
{ fprintf(stderr, " ~"); yyval = (~yyvsp[0]) & 0xffff; }
|
||||
#line 73 "stella.y"
|
||||
{ fprintf(stderr, " ~"); }
|
||||
break;
|
||||
case 22:
|
||||
#line 63 "stella.y"
|
||||
{ fprintf(stderr, " <"); yyval = yyvsp[0] & 0xff; }
|
||||
#line 74 "stella.y"
|
||||
{ fprintf(stderr, " <"); }
|
||||
break;
|
||||
case 23:
|
||||
#line 64 "stella.y"
|
||||
{ fprintf(stderr, " >"); yyval = (yyvsp[0] >> 8) & 0xff; }
|
||||
#line 75 "stella.y"
|
||||
{ fprintf(stderr, " >"); }
|
||||
break;
|
||||
case 24:
|
||||
#line 65 "stella.y"
|
||||
{ fprintf(stderr, " ()"); yyval = yyvsp[-1]; }
|
||||
#line 76 "stella.y"
|
||||
{ fprintf(stderr, " ()"); }
|
||||
break;
|
||||
case 25:
|
||||
#line 66 "stella.y"
|
||||
{ fprintf(stderr, " %d", yyvsp[0]); }
|
||||
#line 77 "stella.y"
|
||||
{ fprintf(stderr, " %d", yyvsp[0].val); yyval.exp = new ConstExpression(yyvsp[0].val); }
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1265,5 +1275,5 @@ yyreturn:
|
|||
#endif
|
||||
return yyresult;
|
||||
}
|
||||
#line 68 "stella.y"
|
||||
#line 79 "stella.y"
|
||||
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
#ifndef BISON_Y_TAB_H
|
||||
# define BISON_Y_TAB_H
|
||||
|
||||
# ifndef YYSTYPE
|
||||
# define YYSTYPE int
|
||||
# define YYSTYPE_IS_TRIVIAL 1
|
||||
# endif
|
||||
#ifndef YYSTYPE
|
||||
typedef union {
|
||||
int val;
|
||||
Expression *exp;
|
||||
} yystype;
|
||||
# define YYSTYPE yystype
|
||||
# define YYSTYPE_IS_TRIVIAL 1
|
||||
#endif
|
||||
# define NUMBER 257
|
||||
# define LOG_OR 258
|
||||
# define LOG_AND 259
|
||||
|
|
Loading…
Reference in New Issue