Mercurial > hg > Members > nobuyasu > myCompiler
diff Bison-Flex/BasicCompiler-MemoryBase/script-parser.cc @ 4:805d39d28230
add Compiler-stackbase
author | nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 17 May 2011 08:00:38 +0900 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Bison-Flex/BasicCompiler-MemoryBase/script-parser.cc Tue May 17 08:00:38 2011 +0900 @@ -0,0 +1,1070 @@ +/* A Bison parser, made by GNU Bison 2.3. */ + +/* Skeleton implementation for Bison LALR(1) parsers in C++ + + Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + special exception, which will cause the skeleton and the resulting + Bison output files to be licensed under the GNU General Public + License without this special exception. + + This special exception was added by the Free Software Foundation in + version 2.2 of Bison. */ + + +#include "script-parser.hh" + +/* User implementation prologue. */ +#line 36 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + +#include "compiler.h" + + +/* Line 317 of lalr1.cc. */ +#line 46 "script-parser.cc" + +#ifndef YY_ +# if YYENABLE_NLS +# if ENABLE_NLS +# include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */ +# define YY_(msgid) dgettext ("bison-runtime", msgid) +# endif +# endif +# ifndef YY_ +# define YY_(msgid) msgid +# endif +#endif + +/* Suppress unused-variable warnings by "using" E. */ +#define YYUSE(e) ((void) (e)) + +/* A pseudo ostream that takes yydebug_ into account. */ +# define YYCDEBUG \ + for (bool yydebugcond_ = yydebug_; yydebugcond_; yydebugcond_ = false) \ + (*yycdebug_) + +/* Enable debugging if requested. */ +#if YYDEBUG + +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ +do { \ + if (yydebug_) \ + { \ + *yycdebug_ << Title << ' '; \ + yy_symbol_print_ ((Type), (Value), (Location)); \ + *yycdebug_ << std::endl; \ + } \ +} while (false) + +# define YY_REDUCE_PRINT(Rule) \ +do { \ + if (yydebug_) \ + yy_reduce_print_ (Rule); \ +} while (false) + +# define YY_STACK_PRINT() \ +do { \ + if (yydebug_) \ + yystack_print_ (); \ +} while (false) + +#else /* !YYDEBUG */ + +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) +# define YY_REDUCE_PRINT(Rule) +# define YY_STACK_PRINT() + +#endif /* !YYDEBUG */ + +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrorlab + +namespace yy +{ +#if YYERROR_VERBOSE + + /* Return YYSTR after stripping away unnecessary quotes and + backslashes, so that it's suitable for yyerror. The heuristic is + that double-quoting is unnecessary unless the string contains an + apostrophe, a comma, or backslash (other than backslash-backslash). + YYSTR is taken from yytname. */ + std::string + script_parser::yytnamerr_ (const char *yystr) + { + if (*yystr == '"') + { + std::string yyr = ""; + char const *yyp = yystr; + + for (;;) + switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + /* Fall through. */ + default: + yyr += *yyp; + break; + + case '"': + return yyr; + } + do_not_strip_quotes: ; + } + + return yystr; + } + +#endif + + /// Build a parser object. + script_parser::script_parser (compiler& driver_yyarg) + : yydebug_ (false), + yycdebug_ (&std::cerr), + driver (driver_yyarg) + { + } + + script_parser::~script_parser () + { + } + +#if YYDEBUG + /*--------------------------------. + | Print this symbol on YYOUTPUT. | + `--------------------------------*/ + + inline void + script_parser::yy_symbol_value_print_ (int yytype, + const semantic_type* yyvaluep, const location_type* yylocationp) + { + YYUSE (yylocationp); + YYUSE (yyvaluep); + switch (yytype) + { + default: + break; + } + } + + + void + script_parser::yy_symbol_print_ (int yytype, + const semantic_type* yyvaluep, const location_type* yylocationp) + { + *yycdebug_ << (yytype < yyntokens_ ? "token" : "nterm") + << ' ' << yytname_[yytype] << " (" + << *yylocationp << ": "; + yy_symbol_value_print_ (yytype, yyvaluep, yylocationp); + *yycdebug_ << ')'; + } +#endif /* ! YYDEBUG */ + + void + script_parser::yydestruct_ (const char* yymsg, + int yytype, semantic_type* yyvaluep, location_type* yylocationp) + { + YYUSE (yylocationp); + YYUSE (yymsg); + YYUSE (yyvaluep); + + YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); + + switch (yytype) + { + case 4: /* "\"identifier\"" */ +#line 68 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { delete (yyvaluep->sval); }; +#line 206 "script-parser.cc" + break; + case 39: /* "assign" */ +#line 71 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { delete (yyvaluep->assign); }; +#line 211 "script-parser.cc" + break; + case 40: /* "comp_expr" */ +#line 74 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { delete (yyvaluep->expr); }; +#line 216 "script-parser.cc" + break; + case 41: /* "expr" */ +#line 73 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { delete (yyvaluep->expr); }; +#line 221 "script-parser.cc" + break; + case 42: /* "value" */ +#line 72 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { delete (yyvaluep->expr); }; +#line 226 "script-parser.cc" + break; + case 43: /* "args" */ +#line 70 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { delete (yyvaluep->args); }; +#line 231 "script-parser.cc" + break; + + default: + break; + } + } + + void + script_parser::yypop_ (unsigned int n) + { + yystate_stack_.pop (n); + yysemantic_stack_.pop (n); + yylocation_stack_.pop (n); + } + + std::ostream& + script_parser::debug_stream () const + { + return *yycdebug_; + } + + void + script_parser::set_debug_stream (std::ostream& o) + { + yycdebug_ = &o; + } + + + script_parser::debug_level_type + script_parser::debug_level () const + { + return yydebug_; + } + + void + script_parser::set_debug_level (debug_level_type l) + { + yydebug_ = l; + } + + + int + script_parser::parse () + { + /// Look-ahead and look-ahead in internal form. + int yychar = yyempty_; + int yytoken = 0; + + /* State. */ + int yyn; + int yylen = 0; + int yystate = 0; + + /* Error handling. */ + int yynerrs_ = 0; + int yyerrstatus_ = 0; + + /// Semantic value of the look-ahead. + semantic_type yylval; + /// Location of the look-ahead. + location_type yylloc; + /// The locations where the error started and ended. + location yyerror_range[2]; + + /// $$. + semantic_type yyval; + /// @$. + location_type yyloc; + + int yyresult; + + YYCDEBUG << "Starting parse" << std::endl; + + + /* User initialization code. */ + #line 20 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" +{ + // ロケーション初期化 + yylloc.begin.filename = yylloc.end.filename = &driver.get_filename(); +} + /* Line 555 of yacc.c. */ +#line 313 "script-parser.cc" + /* Initialize the stacks. The initial state will be pushed in + yynewstate, since the latter expects the semantical and the + location values to have been already stored, initialize these + stacks with a primary value. */ + yystate_stack_ = state_stack_type (0); + yysemantic_stack_ = semantic_stack_type (0); + yylocation_stack_ = location_stack_type (0); + yysemantic_stack_.push (yylval); + yylocation_stack_.push (yylloc); + + /* New state. */ + yynewstate: + yystate_stack_.push (yystate); + YYCDEBUG << "Entering state " << yystate << std::endl; + goto yybackup; + + /* Backup. */ + yybackup: + + /* Try to take a decision without look-ahead. */ + yyn = yypact_[yystate]; + if (yyn == yypact_ninf_) + goto yydefault; + + /* Read a look-ahead token. */ + if (yychar == yyempty_) + { + YYCDEBUG << "Reading a token: "; + yychar = yylex (&yylval, &yylloc, driver); + } + + + /* Convert token to internal form. */ + if (yychar <= yyeof_) + { + yychar = yytoken = yyeof_; + YYCDEBUG << "Now at end of input." << std::endl; + } + else + { + yytoken = yytranslate_ (yychar); + YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); + } + + /* If the proper action on seeing token YYTOKEN is to reduce or to + detect an error, take that action. */ + yyn += yytoken; + if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yytoken) + goto yydefault; + + /* Reduce or error. */ + yyn = yytable_[yyn]; + if (yyn <= 0) + { + if (yyn == 0 || yyn == yytable_ninf_) + goto yyerrlab; + yyn = -yyn; + goto yyreduce; + } + + /* Accept? */ + if (yyn == yyfinal_) + goto yyacceptlab; + + /* Shift the look-ahead token. */ + YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); + + /* Discard the token being shifted unless it is eof. */ + if (yychar != yyeof_) + yychar = yyempty_; + + yysemantic_stack_.push (yylval); + yylocation_stack_.push (yylloc); + + /* Count tokens shifted since error; after three, turn off error + status. */ + if (yyerrstatus_) + --yyerrstatus_; + + yystate = yyn; + goto yynewstate; + + /*-----------------------------------------------------------. + | yydefault -- do the default action for the current state. | + `-----------------------------------------------------------*/ + yydefault: + yyn = yydefact_[yystate]; + if (yyn == 0) + goto yyerrlab; + goto yyreduce; + + /*-----------------------------. + | yyreduce -- Do a reduction. | + `-----------------------------*/ + yyreduce: + yylen = yyr2_[yyn]; + /* If YYLEN is nonzero, implement the default value of the action: + `$$ = $1'. Otherwise, use the top of the stack. + + Otherwise, the following line sets YYVAL to garbage. + This behavior is undocumented and Bison + users should not rely upon it. */ + if (yylen) + yyval = yysemantic_stack_[yylen - 1]; + else + yyval = yysemantic_stack_[0]; + + { + slice<location_type, location_stack_type> slice (yylocation_stack_, yylen); + YYLLOC_DEFAULT (yyloc, slice, yylen); + } + YY_REDUCE_PRINT (yyn); + switch (yyn) + { + case 6: +#line 90 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { driver.EndStatement((yylocation_stack_[(1) - (1)])); ;} + break; + + case 7: +#line 91 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { driver.AssignStatement((yylocation_stack_[(1) - (1)]), (yysemantic_stack_[(1) - (1)].assign)); ;} + break; + + case 8: +#line 92 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { driver.IfStatement((yylocation_stack_[(3) - (1)]), (yysemantic_stack_[(3) - (2)].expr)); ;} + break; + + case 9: +#line 93 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { driver.ElseStatement((yylocation_stack_[(1) - (1)])); ;} + break; + + case 10: +#line 94 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { driver.EndifStatement((yylocation_stack_[(1) - (1)])); ;} + break; + + case 11: +#line 95 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { driver.ForStatement((yylocation_stack_[(6) - (1)]), (yysemantic_stack_[(6) - (2)].assign), (yysemantic_stack_[(6) - (4)].expr), (yysemantic_stack_[(6) - (6)].expr)); ;} + break; + + case 12: +#line 96 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { driver.ForStatement((yylocation_stack_[(4) - (1)]), (yysemantic_stack_[(4) - (2)].assign), (yysemantic_stack_[(4) - (4)].expr), NULL); ;} + break; + + case 13: +#line 97 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { driver.NextStatement((yylocation_stack_[(1) - (1)])); ;} + break; + + case 14: +#line 98 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { driver.WhileStatement((yylocation_stack_[(2) - (1)]), (yysemantic_stack_[(2) - (2)].expr)); ;} + break; + + case 15: +#line 99 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { driver.WendStatement((yylocation_stack_[(1) - (1)])); ;} + break; + + case 16: +#line 100 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { driver.PrintStatement((yylocation_stack_[(2) - (1)]), (yysemantic_stack_[(2) - (2)].args)); ;} + break; + + case 18: +#line 104 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { (yyval.assign) = new CAssign((yylocation_stack_[(3) - (1)]), '=', (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} + break; + + case 19: +#line 107 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_EQ, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} + break; + + case 20: +#line 108 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_NE, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} + break; + + case 21: +#line 109 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_GT, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} + break; + + case 22: +#line 110 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_GE, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} + break; + + case 23: +#line 111 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_LT, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} + break; + + case 24: +#line 112 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_LE, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} + break; + + case 25: +#line 115 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_MINUS, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} + break; + + case 26: +#line 116 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_PLUS, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} + break; + + case 27: +#line 117 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_TIMES, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} + break; + + case 28: +#line 118 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_DIVIDE, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} + break; + + case 29: +#line 119 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_MOD, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} + break; + + case 30: +#line 120 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(2) - (1)]), OP_NEG, (yysemantic_stack_[(2) - (2)].expr)); ;} + break; + + case 31: +#line 121 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { (yyval.expr) = (yysemantic_stack_[(3) - (2)].expr); ;} + break; + + case 32: +#line 122 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { (yyval.expr) = (yysemantic_stack_[(1) - (1)].expr); ;} + break; + + case 33: +#line 123 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { (yyval.expr) = new CNode((yylocation_stack_[(1) - (1)]), OP_CONST, (yysemantic_stack_[(1) - (1)].ival)); ;} + break; + + case 34: +#line 124 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { (yyval.expr) = new CNode((yylocation_stack_[(4) - (1)]), OP_RANDFUNC, (yysemantic_stack_[(4) - (3)].expr)); ;} + break; + + case 35: +#line 127 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { (yyval.expr) = new CValueNode((yylocation_stack_[(1) - (1)]), (yysemantic_stack_[(1) - (1)].sval)); ;} + break; + + case 36: +#line 130 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { (yyval.args) = new CArgs((yylocation_stack_[(1) - (1)]), (yysemantic_stack_[(1) - (1)].expr)); ;} + break; + + case 37: +#line 131 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + { (yyval.args) = (yysemantic_stack_[(3) - (1)].args)->Add((yylocation_stack_[(3) - (3)]), (yysemantic_stack_[(3) - (3)].expr)); ;} + break; + + + /* Line 675 of lalr1.cc. */ +#line 585 "script-parser.cc" + default: break; + } + YY_SYMBOL_PRINT ("-> $$ =", yyr1_[yyn], &yyval, &yyloc); + + yypop_ (yylen); + yylen = 0; + YY_STACK_PRINT (); + + yysemantic_stack_.push (yyval); + yylocation_stack_.push (yyloc); + + /* Shift the result of the reduction. */ + yyn = yyr1_[yyn]; + yystate = yypgoto_[yyn - yyntokens_] + yystate_stack_[0]; + if (0 <= yystate && yystate <= yylast_ + && yycheck_[yystate] == yystate_stack_[0]) + yystate = yytable_[yystate]; + else + yystate = yydefgoto_[yyn - yyntokens_]; + goto yynewstate; + + /*------------------------------------. + | yyerrlab -- here on detecting error | + `------------------------------------*/ + yyerrlab: + /* If not already recovering from an error, report this error. */ + if (!yyerrstatus_) + { + ++yynerrs_; + error (yylloc, yysyntax_error_ (yystate, yytoken)); + } + + yyerror_range[0] = yylloc; + if (yyerrstatus_ == 3) + { + /* If just tried and failed to reuse look-ahead token after an + error, discard it. */ + + if (yychar <= yyeof_) + { + /* Return failure if at end of input. */ + if (yychar == yyeof_) + YYABORT; + } + else + { + yydestruct_ ("Error: discarding", yytoken, &yylval, &yylloc); + yychar = yyempty_; + } + } + + /* Else will try to reuse look-ahead token after shifting the error + token. */ + goto yyerrlab1; + + + /*---------------------------------------------------. + | yyerrorlab -- error raised explicitly by YYERROR. | + `---------------------------------------------------*/ + yyerrorlab: + + /* Pacify compilers like GCC when the user code never invokes + YYERROR and the label yyerrorlab therefore never appears in user + code. */ + if (false) + goto yyerrorlab; + + yyerror_range[0] = yylocation_stack_[yylen - 1]; + /* Do not reclaim the symbols of the rule which action triggered + this YYERROR. */ + yypop_ (yylen); + yylen = 0; + yystate = yystate_stack_[0]; + goto yyerrlab1; + + /*-------------------------------------------------------------. + | yyerrlab1 -- common code for both syntax error and YYERROR. | + `-------------------------------------------------------------*/ + yyerrlab1: + yyerrstatus_ = 3; /* Each real token shifted decrements this. */ + + for (;;) + { + yyn = yypact_[yystate]; + if (yyn != yypact_ninf_) + { + yyn += yyterror_; + if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_) + { + yyn = yytable_[yyn]; + if (0 < yyn) + break; + } + } + + /* Pop the current state because it cannot handle the error token. */ + if (yystate_stack_.height () == 1) + YYABORT; + + yyerror_range[0] = yylocation_stack_[0]; + yydestruct_ ("Error: popping", + yystos_[yystate], + &yysemantic_stack_[0], &yylocation_stack_[0]); + yypop_ (); + yystate = yystate_stack_[0]; + YY_STACK_PRINT (); + } + + if (yyn == yyfinal_) + goto yyacceptlab; + + yyerror_range[1] = yylloc; + // Using YYLLOC is tempting, but would change the location of + // the look-ahead. YYLOC is available though. + YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2); + yysemantic_stack_.push (yylval); + yylocation_stack_.push (yyloc); + + /* Shift the error token. */ + YY_SYMBOL_PRINT ("Shifting", yystos_[yyn], + &yysemantic_stack_[0], &yylocation_stack_[0]); + + yystate = yyn; + goto yynewstate; + + /* Accept. */ + yyacceptlab: + yyresult = 0; + goto yyreturn; + + /* Abort. */ + yyabortlab: + yyresult = 1; + goto yyreturn; + + yyreturn: + if (yychar != yyeof_ && yychar != yyempty_) + yydestruct_ ("Cleanup: discarding lookahead", yytoken, &yylval, &yylloc); + + /* Do not reclaim the symbols of the rule which action triggered + this YYABORT or YYACCEPT. */ + yypop_ (yylen); + while (yystate_stack_.height () != 1) + { + yydestruct_ ("Cleanup: popping", + yystos_[yystate_stack_[0]], + &yysemantic_stack_[0], + &yylocation_stack_[0]); + yypop_ (); + } + + return yyresult; + } + + // Generate an error message. + std::string + script_parser::yysyntax_error_ (int yystate, int tok) + { + std::string res; + YYUSE (yystate); +#if YYERROR_VERBOSE + int yyn = yypact_[yystate]; + if (yypact_ninf_ < yyn && yyn <= yylast_) + { + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = yylast_ - yyn + 1; + int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_; + int count = 0; + for (int x = yyxbegin; x < yyxend; ++x) + if (yycheck_[x + yyn] == x && x != yyterror_) + ++count; + + // FIXME: This method of building the message is not compatible + // with internationalization. It should work like yacc.c does it. + // That is, first build a string that looks like this: + // "syntax error, unexpected %s or %s or %s" + // Then, invoke YY_ on this string. + // Finally, use the string as a format to output + // yytname_[tok], etc. + // Until this gets fixed, this message appears in English only. + res = "syntax error, unexpected "; + res += yytnamerr_ (yytname_[tok]); + if (count < 5) + { + count = 0; + for (int x = yyxbegin; x < yyxend; ++x) + if (yycheck_[x + yyn] == x && x != yyterror_) + { + res += (!count++) ? ", expecting " : " or "; + res += yytnamerr_ (yytname_[x]); + } + } + } + else +#endif + res = YY_("syntax error"); + return res; + } + + + /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ + const signed char script_parser::yypact_ninf_ = -23; + const signed char + script_parser::yypact_[] = + { + 85, -23, -23, -23, 19, -23, -23, -3, -23, 19, + -23, -23, 19, 66, -23, -7, -23, -22, -23, -14, + 19, 19, 8, 38, -23, 9, -23, 103, 4, -23, + -23, -23, 19, 19, -23, 86, -23, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 103, 91, -23, 103, 103, 103, 103, -20, -20, -23, + -23, -23, 103, 103, -11, 103, -23, 19, 103 + }; + + /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE + doesn't specify something else to do. Zero means the default is an + error. */ + const unsigned char + script_parser::yydefact_[] = + { + 0, 17, 35, 5, 0, 9, 10, 0, 13, 0, + 15, 6, 0, 0, 2, 0, 7, 0, 33, 0, + 0, 0, 0, 0, 32, 0, 14, 36, 16, 1, + 3, 4, 0, 0, 30, 0, 8, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 18, 0, 31, 19, 20, 22, 24, 26, 25, 27, + 28, 29, 21, 23, 12, 37, 34, 0, 11 + }; + + /* YYPGOTO[NTERM-NUM]. */ + const signed char + script_parser::yypgoto_[] = + { + -23, -23, 27, -23, 34, 39, -12, 3, -23 + }; + + /* YYDEFGOTO[NTERM-NUM]. */ + const signed char + script_parser::yydefgoto_[] = + { + -1, 13, 14, 15, 16, 22, 23, 24, 28 + }; + + /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule which + number is the opposite. If zero, do what YYDEFACT says. */ + const signed char script_parser::yytable_ninf_ = -1; + const unsigned char + script_parser::yytable_[] = + { + 27, 2, 31, 17, 43, 44, 45, 32, 34, 35, + 17, 41, 42, 43, 44, 45, 17, 67, 33, 36, + 50, 51, 18, 2, 48, 53, 54, 55, 56, 57, + 58, 59, 60, 61, 62, 63, 64, 65, 49, 19, + 30, 25, 20, 37, 38, 39, 40, 0, 26, 0, + 0, 21, 0, 0, 0, 68, 0, 0, 0, 0, + 41, 42, 43, 44, 45, 0, 29, 1, 46, 47, + 2, 0, 0, 0, 0, 3, 4, 0, 5, 6, + 7, 0, 8, 9, 10, 11, 1, 12, 0, 2, + 0, 0, 0, 0, 3, 4, 0, 5, 6, 7, + 0, 8, 9, 10, 11, 0, 12, 0, 41, 42, + 43, 44, 45, 41, 42, 43, 44, 45, 0, 52, + 0, 0, 0, 0, 66, 41, 42, 43, 44, 45 + }; + + /* YYCHECK. */ + const signed char + script_parser::yycheck_[] = + { + 12, 4, 9, 0, 24, 25, 26, 29, 20, 21, + 7, 22, 23, 24, 25, 26, 13, 28, 32, 11, + 32, 33, 3, 4, 15, 37, 38, 39, 40, 41, + 42, 43, 44, 45, 46, 47, 48, 49, 34, 20, + 13, 7, 23, 5, 6, 7, 8, -1, 9, -1, + -1, 32, -1, -1, -1, 67, -1, -1, -1, -1, + 22, 23, 24, 25, 26, -1, 0, 1, 30, 31, + 4, -1, -1, -1, -1, 9, 10, -1, 12, 13, + 14, -1, 16, 17, 18, 19, 1, 21, -1, 4, + -1, -1, -1, -1, 9, 10, -1, 12, 13, 14, + -1, 16, 17, 18, 19, -1, 21, -1, 22, 23, + 24, 25, 26, 22, 23, 24, 25, 26, -1, 33, + -1, -1, -1, -1, 33, 22, 23, 24, 25, 26 + }; + + /* STOS_[STATE-NUM] -- The (internal number of the) accessing + symbol of state STATE-NUM. */ + const unsigned char + script_parser::yystos_[] = + { + 0, 1, 4, 9, 10, 12, 13, 14, 16, 17, + 18, 19, 21, 36, 37, 38, 39, 42, 3, 20, + 23, 32, 40, 41, 42, 39, 40, 41, 43, 0, + 37, 9, 29, 32, 41, 41, 11, 5, 6, 7, + 8, 22, 23, 24, 25, 26, 30, 31, 15, 34, + 41, 41, 33, 41, 41, 41, 41, 41, 41, 41, + 41, 41, 41, 41, 41, 41, 33, 28, 41 + }; + +#if YYDEBUG + /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding + to YYLEX-NUM. */ + const unsigned short int + script_parser::yytoken_number_[] = + { + 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, + 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, + 275, 276, 43, 45, 42, 47, 37, 277, 278, 61, + 62, 60, 40, 41, 44 + }; +#endif + + /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ + const unsigned char + script_parser::yyr1_[] = + { + 0, 35, 36, 36, 37, 37, 38, 38, 38, 38, + 38, 38, 38, 38, 38, 38, 38, 38, 39, 40, + 40, 40, 40, 40, 40, 41, 41, 41, 41, 41, + 41, 41, 41, 41, 41, 42, 43, 43 + }; + + /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ + const unsigned char + script_parser::yyr2_[] = + { + 0, 2, 1, 2, 2, 1, 1, 1, 3, 1, + 1, 6, 4, 1, 2, 1, 2, 1, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 2, 3, 1, 1, 4, 1, 1, 3 + }; + +#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE + /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + First, the terminals, then, starting at \a yyntokens_, nonterminals. */ + const char* + const script_parser::yytname_[] = + { + "\"end of file\"", "error", "$undefined", "\"ival\"", "\"identifier\"", + "\"==\"", "\"!=\"", "\">=\"", "\"<=\"", "\"\\n\"", "\"if\"", "\"then\"", + "\"else\"", "\"endif\"", "\"for\"", "\"to\"", "\"next\"", "\"while\"", + "\"wend\"", "\"end\"", "\"rand\"", "\"print\"", "'+'", "'-'", "'*'", + "'/'", "'%'", "NEG", "\"step\"", "'='", "'>'", "'<'", "'('", "')'", + "','", "$accept", "unit", "states", "statement", "assign", "comp_expr", + "expr", "value", "args", 0 + }; +#endif + +#if YYDEBUG + /* YYRHS -- A `-1'-separated list of the rules' RHS. */ + const script_parser::rhs_number_type + script_parser::yyrhs_[] = + { + 36, 0, -1, 37, -1, 36, 37, -1, 38, 9, + -1, 9, -1, 19, -1, 39, -1, 10, 40, 11, + -1, 12, -1, 13, -1, 14, 39, 15, 41, 28, + 41, -1, 14, 39, 15, 41, -1, 16, -1, 17, + 40, -1, 18, -1, 21, 43, -1, 1, -1, 42, + 29, 41, -1, 41, 5, 41, -1, 41, 6, 41, + -1, 41, 30, 41, -1, 41, 7, 41, -1, 41, + 31, 41, -1, 41, 8, 41, -1, 41, 23, 41, + -1, 41, 22, 41, -1, 41, 24, 41, -1, 41, + 25, 41, -1, 41, 26, 41, -1, 23, 41, -1, + 32, 41, 33, -1, 42, -1, 3, -1, 20, 32, + 41, 33, -1, 4, -1, 41, -1, 43, 34, 41, + -1 + }; + + /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in + YYRHS. */ + const unsigned char + script_parser::yyprhs_[] = + { + 0, 0, 3, 5, 8, 11, 13, 15, 17, 21, + 23, 25, 32, 37, 39, 42, 44, 47, 49, 53, + 57, 61, 65, 69, 73, 77, 81, 85, 89, 93, + 97, 100, 104, 106, 108, 113, 115, 117 + }; + + /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ + const unsigned char + script_parser::yyrline_[] = + { + 0, 82, 82, 83, 86, 87, 90, 91, 92, 93, + 94, 95, 96, 97, 98, 99, 100, 101, 104, 107, + 108, 109, 110, 111, 112, 115, 116, 117, 118, 119, + 120, 121, 122, 123, 124, 127, 130, 131 + }; + + // Print the state stack on the debug stream. + void + script_parser::yystack_print_ () + { + *yycdebug_ << "Stack now"; + for (state_stack_type::const_iterator i = yystate_stack_.begin (); + i != yystate_stack_.end (); ++i) + *yycdebug_ << ' ' << *i; + *yycdebug_ << std::endl; + } + + // Report on the debug stream that the rule \a yyrule is going to be reduced. + void + script_parser::yy_reduce_print_ (int yyrule) + { + unsigned int yylno = yyrline_[yyrule]; + int yynrhs = yyr2_[yyrule]; + /* Print the symbols being reduced, and their result. */ + *yycdebug_ << "Reducing stack by rule " << yyrule - 1 + << " (line " << yylno << "), "; + /* The symbols being reduced. */ + for (int yyi = 0; yyi < yynrhs; yyi++) + YY_SYMBOL_PRINT (" $" << yyi + 1 << " =", + yyrhs_[yyprhs_[yyrule] + yyi], + &(yysemantic_stack_[(yynrhs) - (yyi + 1)]), + &(yylocation_stack_[(yynrhs) - (yyi + 1)])); + } +#endif // YYDEBUG + + /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ + script_parser::token_number_type + script_parser::yytranslate_ (int t) + { + static + const token_number_type + translate_table[] = + { + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 26, 2, 2, + 32, 33, 24, 22, 34, 23, 2, 25, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 31, 29, 30, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, + 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 27, 28 + }; + if ((unsigned int) t <= yyuser_token_number_max_) + return translate_table[t]; + else + return yyundef_token_; + } + + const int script_parser::yyeof_ = 0; + const int script_parser::yylast_ = 129; + const int script_parser::yynnts_ = 9; + const int script_parser::yyempty_ = -2; + const int script_parser::yyfinal_ = 29; + const int script_parser::yyterror_ = 1; + const int script_parser::yyerrcode_ = 256; + const int script_parser::yyntokens_ = 35; + + const unsigned int script_parser::yyuser_token_number_max_ = 278; + const script_parser::token_number_type script_parser::yyundef_token_ = 2; + +} // namespace yy + +#line 134 "d:\\Work\\ScriptEngine\\Sample Source\\Bison-Flex\\BasicCompiler-MemoryBase\\script-parser.yy" + +void yy::script_parser::error(const yy::script_parser::location_type& l, const std::string& m) +{ + driver.error(l, m); +} +