# HG changeset patch # User nobuyasu # Date 1304992082 -32400 # Node ID 3cea2e8a0e4ba4d48ed62af75022d9fe8a0e8a6f # Parent fbe42292d479db568a218324cb7bf271d441aa30 add function goto diff -r fbe42292d479 -r 3cea2e8a0e4b Bison-Flex/BasicCompiler-StackBase/UTF8/compiler.cpp --- a/Bison-Flex/BasicCompiler-StackBase/UTF8/compiler.cpp Tue May 10 06:43:55 2011 +0900 +++ b/Bison-Flex/BasicCompiler-StackBase/UTF8/compiler.cpp Tue May 10 10:48:02 2011 +0900 @@ -295,6 +295,20 @@ delete args; } +void compiler::MakeGotoLabel(const yy::location& l, std::string *value) +{ + int label = MakeLabel(); + SetLabel(label); + + gototable.insert( std::map::value_type( *value, label) ); +} + +void compiler::GotoLabel(const yy::location& l, std::string *value) +{ + OpJmp(gototable[*value]); +} + + // ラベル生成 int compiler::MakeLabel() diff -r fbe42292d479 -r 3cea2e8a0e4b Bison-Flex/BasicCompiler-StackBase/UTF8/compiler.h --- a/Bison-Flex/BasicCompiler-StackBase/UTF8/compiler.h Tue May 10 06:43:55 2011 +0900 +++ b/Bison-Flex/BasicCompiler-StackBase/UTF8/compiler.h Tue May 10 10:48:02 2011 +0900 @@ -206,6 +206,12 @@ // print文 void PrintStatement(const yy::location& l, CArgs *args); + // make label for goto + void MakeGotoLabel(const yy::location& l, std::string *string); + // goto + void GotoLabel(const yy::location& l, std::string *string); + + const CValueTag *GetValueTag(const std::string &name) const { return variables.find(name); @@ -246,6 +252,8 @@ std::vector labels; std::stack state_stack; + std::map gototable; + int error_count; std::string file; diff -r fbe42292d479 -r 3cea2e8a0e4b Bison-Flex/BasicCompiler-StackBase/UTF8/file2.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Bison-Flex/BasicCompiler-StackBase/UTF8/file2.txt Tue May 10 10:48:02 2011 +0900 @@ -0,0 +1,10 @@ +a = 0 + +L1 : + +a = a + 1 +print a + +if a < 3 then + goto L1 +endif diff -r fbe42292d479 -r 3cea2e8a0e4b Bison-Flex/BasicCompiler-StackBase/UTF8/script-parser.cc --- a/Bison-Flex/BasicCompiler-StackBase/UTF8/script-parser.cc Tue May 10 06:43:55 2011 +0900 +++ b/Bison-Flex/BasicCompiler-StackBase/UTF8/script-parser.cc Tue May 10 10:48:02 2011 +0900 @@ -45,7 +45,7 @@ #line 46 "script-parser.cc" #ifndef YY_ -# if YYENABLE_NLS +# if defined YYENABLE_NLS && YYENABLE_NLS # if ENABLE_NLS # include /* FIXME: INFRINGES ON USER NAME SPACE */ # define YY_(msgid) dgettext ("bison-runtime", msgid) @@ -200,32 +200,32 @@ switch (yytype) { case 4: /* "\"identifier\"" */ -#line 68 "script-parser.yy" +#line 70 "script-parser.yy" { delete (yyvaluep->sval); }; #line 206 "script-parser.cc" break; - case 39: /* "assign" */ -#line 71 "script-parser.yy" + case 41: /* "assign" */ +#line 73 "script-parser.yy" { delete (yyvaluep->assign); }; #line 211 "script-parser.cc" break; - case 40: /* "comp_expr" */ -#line 74 "script-parser.yy" + case 42: /* "comp_expr" */ +#line 76 "script-parser.yy" { delete (yyvaluep->expr); }; #line 216 "script-parser.cc" break; - case 41: /* "expr" */ -#line 73 "script-parser.yy" + case 43: /* "expr" */ +#line 75 "script-parser.yy" { delete (yyvaluep->expr); }; #line 221 "script-parser.cc" break; - case 42: /* "value" */ -#line 72 "script-parser.yy" + case 44: /* "value" */ +#line 74 "script-parser.yy" { delete (yyvaluep->expr); }; #line 226 "script-parser.cc" break; - case 43: /* "args" */ -#line 70 "script-parser.yy" + case 45: /* "args" */ +#line 72 "script-parser.yy" { delete (yyvaluep->args); }; #line 231 "script-parser.cc" break; @@ -308,7 +308,7 @@ // ロケーション初期化 yylloc.begin.filename = yylloc.end.filename = &driver.get_filename(); } - /* Line 547 of yacc.c. */ + /* 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 @@ -425,163 +425,173 @@ switch (yyn) { case 6: -#line 90 "script-parser.yy" +#line 92 "script-parser.yy" { driver.EndStatement((yylocation_stack_[(1) - (1)])); ;} break; case 7: -#line 91 "script-parser.yy" +#line 93 "script-parser.yy" { driver.AssignStatement((yylocation_stack_[(1) - (1)]), (yysemantic_stack_[(1) - (1)].assign)); ;} break; case 8: -#line 92 "script-parser.yy" +#line 94 "script-parser.yy" { driver.IfStatement((yylocation_stack_[(3) - (1)]), (yysemantic_stack_[(3) - (2)].expr)); ;} break; case 9: -#line 93 "script-parser.yy" +#line 95 "script-parser.yy" { driver.ElseStatement((yylocation_stack_[(1) - (1)])); ;} break; case 10: -#line 94 "script-parser.yy" +#line 96 "script-parser.yy" { driver.EndifStatement((yylocation_stack_[(1) - (1)])); ;} break; case 11: -#line 95 "script-parser.yy" +#line 97 "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 "script-parser.yy" +#line 98 "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 "script-parser.yy" +#line 99 "script-parser.yy" { driver.NextStatement((yylocation_stack_[(1) - (1)])); ;} break; case 14: -#line 98 "script-parser.yy" +#line 100 "script-parser.yy" { driver.WhileStatement((yylocation_stack_[(2) - (1)]), (yysemantic_stack_[(2) - (2)].expr)); ;} break; case 15: -#line 99 "script-parser.yy" +#line 101 "script-parser.yy" { driver.WendStatement((yylocation_stack_[(1) - (1)])); ;} break; case 16: -#line 100 "script-parser.yy" +#line 102 "script-parser.yy" { driver.PrintStatement((yylocation_stack_[(2) - (1)]), (yysemantic_stack_[(2) - (2)].args)); ;} break; + case 17: +#line 103 "script-parser.yy" + { driver.MakeGotoLabel((yylocation_stack_[(2) - (1)]), (yysemantic_stack_[(2) - (1)].sval)); ;} + break; + case 18: #line 104 "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 "script-parser.yy" - { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_EQ, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} + { driver.GotoLabel((yylocation_stack_[(2) - (1)]), (yysemantic_stack_[(2) - (2)].sval)); ;} break; case 20: #line 108 "script-parser.yy" - { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_NE, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} + { (yyval.assign) = new CAssign((yylocation_stack_[(3) - (1)]), '=', (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} break; case 21: -#line 109 "script-parser.yy" - { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_GT, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} +#line 111 "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 22: -#line 110 "script-parser.yy" - { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_GE, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} +#line 112 "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 23: -#line 111 "script-parser.yy" - { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_LT, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} +#line 113 "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 24: -#line 112 "script-parser.yy" - { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_LE, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} +#line 114 "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 25: #line 115 "script-parser.yy" - { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_MINUS, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} + { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_LT, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} break; case 26: #line 116 "script-parser.yy" - { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_PLUS, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} + { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_LE, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} break; case 27: -#line 117 "script-parser.yy" - { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_TIMES, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} +#line 119 "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 28: -#line 118 "script-parser.yy" - { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_DIVIDE, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} +#line 120 "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 29: -#line 119 "script-parser.yy" - { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(3) - (1)]), OP_MOD, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;} +#line 121 "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 30: -#line 120 "script-parser.yy" - { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(2) - (1)]), OP_NEG, (yysemantic_stack_[(2) - (2)].expr)); ;} +#line 122 "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 31: -#line 121 "script-parser.yy" - { (yyval.expr) = (yysemantic_stack_[(3) - (2)].expr); ;} +#line 123 "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 32: -#line 122 "script-parser.yy" - { (yyval.expr) = (yysemantic_stack_[(1) - (1)].expr); ;} +#line 124 "script-parser.yy" + { (yyval.expr) = CNode::MakeNode(driver, (yylocation_stack_[(2) - (1)]), OP_NEG, (yysemantic_stack_[(2) - (2)].expr)); ;} break; case 33: -#line 123 "script-parser.yy" - { (yyval.expr) = new CNode((yylocation_stack_[(1) - (1)]), OP_CONST, (yysemantic_stack_[(1) - (1)].ival)); ;} +#line 125 "script-parser.yy" + { (yyval.expr) = (yysemantic_stack_[(3) - (2)].expr); ;} break; case 34: -#line 124 "script-parser.yy" - { (yyval.expr) = new CNode((yylocation_stack_[(4) - (1)]), OP_RANDFUNC, (yysemantic_stack_[(4) - (3)].expr)); ;} +#line 126 "script-parser.yy" + { (yyval.expr) = (yysemantic_stack_[(1) - (1)].expr); ;} break; case 35: #line 127 "script-parser.yy" - { (yyval.expr) = new CValueNode((yylocation_stack_[(1) - (1)]), (yysemantic_stack_[(1) - (1)].sval)); ;} + { (yyval.expr) = new CNode((yylocation_stack_[(1) - (1)]), OP_CONST, (yysemantic_stack_[(1) - (1)].ival)); ;} break; case 36: -#line 130 "script-parser.yy" - { (yyval.args) = new CArgs((yylocation_stack_[(1) - (1)]), (yysemantic_stack_[(1) - (1)].expr)); ;} +#line 128 "script-parser.yy" + { (yyval.expr) = new CNode((yylocation_stack_[(4) - (1)]), OP_RANDFUNC, (yysemantic_stack_[(4) - (3)].expr)); ;} break; case 37: #line 131 "script-parser.yy" + { (yyval.expr) = new CValueNode((yylocation_stack_[(1) - (1)]), (yysemantic_stack_[(1) - (1)].sval)); ;} + break; + + case 38: +#line 135 "script-parser.yy" + { (yyval.args) = new CArgs((yylocation_stack_[(1) - (1)]), (yysemantic_stack_[(1) - (1)].expr)); ;} + break; + + case 39: +#line 136 "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" +#line 595 "script-parser.cc" default: break; } YY_SYMBOL_PRINT ("-> $$ =", yyr1_[yyn], &yyval, &yyloc); @@ -792,13 +802,14 @@ 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 + 90, -23, -15, -23, 23, -23, -23, 5, -23, 23, + -23, -23, 23, 6, 69, -23, 7, -23, -17, -23, + -23, -23, -11, 23, 23, 11, 39, -23, 27, -23, + 91, 18, -23, -23, -23, -23, 23, 23, -23, -22, + -23, 23, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 23, 23, 23, 91, -7, -23, 91, 91, 91, + 91, 34, 34, -23, -23, -23, 91, 91, 25, 91, + -23, 23, 91 }; /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE @@ -807,27 +818,28 @@ 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 + 0, 19, 37, 5, 0, 9, 10, 0, 13, 0, + 15, 6, 0, 0, 0, 2, 0, 7, 0, 17, + 35, 37, 0, 0, 0, 0, 0, 34, 0, 14, + 38, 16, 18, 1, 3, 4, 0, 0, 32, 0, + 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 20, 0, 33, 21, 22, 24, + 26, 28, 27, 29, 30, 31, 23, 25, 12, 39, + 36, 0, 11 }; /* YYPGOTO[NTERM-NUM]. */ const signed char script_parser::yypgoto_[] = { - -23, -23, 27, -23, 34, 39, -12, 3, -23 + -23, -23, 42, -23, 51, 59, -12, 1, -23 }; /* YYDEFGOTO[NTERM-NUM]. */ const signed char script_parser::yydefgoto_[] = { - -1, 13, 14, 15, 16, 22, 23, 24, 28 + -1, 14, 15, 16, 17, 25, 26, 27, 31 }; /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If @@ -837,38 +849,36 @@ 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 + 30, 18, 45, 46, 47, 48, 49, 19, 18, 21, + 32, 38, 39, 56, 36, 18, 35, 45, 46, 47, + 48, 49, 40, 37, 54, 55, 20, 21, 70, 57, + 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, + 68, 69, 52, 22, 41, 42, 43, 44, 23, 45, + 46, 47, 48, 49, 53, 71, 34, 24, 28, 72, + 47, 48, 49, 45, 46, 47, 48, 49, 29, 33, + 1, 50, 51, 2, 0, 0, 0, 0, 3, 4, + 0, 5, 6, 7, 0, 8, 9, 10, 11, 0, + 12, 1, 13, 0, 2, 0, 0, 0, 0, 3, + 4, 0, 5, 6, 7, 0, 8, 9, 10, 11, + 0, 12, 0, 13, 0, 45, 46, 47, 48, 49 }; /* 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 + 12, 0, 24, 25, 26, 27, 28, 22, 7, 4, + 4, 23, 24, 35, 31, 14, 9, 24, 25, 26, + 27, 28, 11, 34, 36, 37, 3, 4, 35, 41, + 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, + 52, 53, 15, 20, 5, 6, 7, 8, 25, 24, + 25, 26, 27, 28, 36, 30, 14, 34, 7, 71, + 26, 27, 28, 24, 25, 26, 27, 28, 9, 0, + 1, 32, 33, 4, -1, -1, -1, -1, 9, 10, + -1, 12, 13, 14, -1, 16, 17, 18, 19, -1, + 21, 1, 23, -1, 4, -1, -1, -1, -1, 9, + 10, -1, 12, 13, 14, -1, 16, 17, 18, 19, + -1, 21, -1, 23, -1, 24, 25, 26, 27, 28 }; /* STOS_[STATE-NUM] -- The (internal number of the) accessing @@ -877,12 +887,13 @@ 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 + 18, 19, 21, 23, 38, 39, 40, 41, 44, 22, + 3, 4, 20, 25, 34, 42, 43, 44, 41, 42, + 43, 45, 4, 0, 39, 9, 31, 34, 43, 43, + 11, 5, 6, 7, 8, 24, 25, 26, 27, 28, + 32, 33, 15, 36, 43, 43, 35, 43, 43, 43, + 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, + 35, 30, 43 }; #if YYDEBUG @@ -893,8 +904,8 @@ { 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 + 275, 276, 277, 278, 43, 45, 42, 47, 37, 279, + 280, 61, 62, 60, 40, 41, 44 }; #endif @@ -902,10 +913,10 @@ 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 + 0, 37, 38, 38, 39, 39, 40, 40, 40, 40, + 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, + 41, 42, 42, 42, 42, 42, 42, 43, 43, 43, + 43, 43, 43, 43, 43, 43, 43, 44, 45, 45 }; /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ @@ -913,9 +924,9 @@ script_parser::yyr2_[] = { 0, 2, 1, 2, 2, 1, 1, 1, 3, 1, - 1, 6, 4, 1, 2, 1, 2, 1, 3, 3, + 1, 6, 4, 1, 2, 1, 2, 2, 2, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 2, 3, 1, 1, 4, 1, 1, 3 + 3, 3, 2, 3, 1, 1, 4, 1, 1, 3 }; #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE @@ -927,10 +938,10 @@ "\"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 + "\"wend\"", "\"end\"", "\"rand\"", "\"print\"", "\":\"", "\"goto\"", + "'+'", "'-'", "'*'", "'/'", "'%'", "NEG", "\"step\"", "'='", "'>'", + "'<'", "'('", "')'", "','", "$accept", "unit", "states", "statement", + "assign", "comp_expr", "expr", "value", "args", 0 }; #endif @@ -939,19 +950,19 @@ 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 + 38, 0, -1, 39, -1, 38, 39, -1, 40, 9, + -1, 9, -1, 19, -1, 41, -1, 10, 42, 11, + -1, 12, -1, 13, -1, 14, 41, 15, 43, 30, + 43, -1, 14, 41, 15, 43, -1, 16, -1, 17, + 42, -1, 18, -1, 21, 45, -1, 4, 22, -1, + 23, 4, -1, 1, -1, 44, 31, 43, -1, 43, + 5, 43, -1, 43, 6, 43, -1, 43, 32, 43, + -1, 43, 7, 43, -1, 43, 33, 43, -1, 43, + 8, 43, -1, 43, 25, 43, -1, 43, 24, 43, + -1, 43, 26, 43, -1, 43, 27, 43, -1, 43, + 28, 43, -1, 25, 43, -1, 34, 43, 35, -1, + 44, -1, 3, -1, 20, 34, 43, 35, -1, 4, + -1, 43, -1, 45, 36, 43, -1 }; /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in @@ -960,19 +971,19 @@ 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 + 23, 25, 32, 37, 39, 42, 44, 47, 50, 53, + 55, 59, 63, 67, 71, 75, 79, 83, 87, 91, + 95, 99, 103, 106, 110, 112, 114, 119, 121, 123 }; /* 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 + 0, 84, 84, 85, 88, 89, 92, 93, 94, 95, + 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, + 108, 111, 112, 113, 114, 115, 116, 119, 120, 121, + 122, 123, 124, 125, 126, 127, 128, 131, 135, 136 }; // Print the state stack on the debug stream. @@ -1015,10 +1026,10 @@ 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, 28, 2, 2, + 34, 35, 26, 24, 36, 25, 2, 27, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 31, 29, 30, 2, 2, 2, 2, 2, 2, 2, + 33, 31, 32, 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, @@ -1039,7 +1050,8 @@ 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 + 15, 16, 17, 18, 19, 20, 21, 22, 23, 29, + 30 }; if ((unsigned int) t <= yyuser_token_number_max_) return translate_table[t]; @@ -1048,20 +1060,20 @@ } const int script_parser::yyeof_ = 0; - const int script_parser::yylast_ = 129; + const int script_parser::yylast_ = 119; const int script_parser::yynnts_ = 9; const int script_parser::yyempty_ = -2; - const int script_parser::yyfinal_ = 29; + const int script_parser::yyfinal_ = 33; const int script_parser::yyterror_ = 1; const int script_parser::yyerrcode_ = 256; - const int script_parser::yyntokens_ = 35; + const int script_parser::yyntokens_ = 37; - const unsigned int script_parser::yyuser_token_number_max_ = 278; + const unsigned int script_parser::yyuser_token_number_max_ = 280; const script_parser::token_number_type script_parser::yyundef_token_ = 2; } // namespace yy -#line 134 "script-parser.yy" +#line 139 "script-parser.yy" void yy::script_parser::error(const yy::script_parser::location_type& l, const std::string& m) { diff -r fbe42292d479 -r 3cea2e8a0e4b Bison-Flex/BasicCompiler-StackBase/UTF8/script-parser.hh --- a/Bison-Flex/BasicCompiler-StackBase/UTF8/script-parser.hh Tue May 10 06:43:55 2011 +0900 +++ b/Bison-Flex/BasicCompiler-StackBase/UTF8/script-parser.hh Tue May 10 10:48:02 2011 +0900 @@ -60,7 +60,7 @@ class compiler; -/* Line 35 of lalr1.cc. */ +/* Line 303 of lalr1.cc. */ #line 65 "script-parser.hh" #include "location.hh" @@ -121,7 +121,7 @@ CNode *expr; CAssign *assign; } -/* Line 35 of lalr1.cc. */ +/* Line 303 of lalr1.cc. */ #line 126 "script-parser.hh" ; #else @@ -154,7 +154,9 @@ TK_END = 274, TK_RAND = 275, TK_PRINT = 276, - NEG = 277 + TK_COLON = 277, + TK_GOTO = 278, + NEG = 279 }; }; diff -r fbe42292d479 -r 3cea2e8a0e4b Bison-Flex/BasicCompiler-StackBase/UTF8/script-parser.output --- a/Bison-Flex/BasicCompiler-StackBase/UTF8/script-parser.output Tue May 10 06:43:55 2011 +0900 +++ b/Bison-Flex/BasicCompiler-StackBase/UTF8/script-parser.output Tue May 10 10:48:02 2011 +0900 @@ -1,4 +1,4 @@ -文法 +Grammar 0 $accept: unit "end of file" @@ -19,55 +19,57 @@ 13 | "while" comp_expr 14 | "wend" 15 | "print" args - 16 | error + 16 | "identifier" ":" + 17 | "goto" "identifier" + 18 | error - 17 assign: value '=' expr + 19 assign: value '=' expr - 18 comp_expr: expr "==" expr - 19 | expr "!=" expr - 20 | expr '>' expr - 21 | expr ">=" expr - 22 | expr '<' expr - 23 | expr "<=" expr + 20 comp_expr: expr "==" expr + 21 | expr "!=" expr + 22 | expr '>' expr + 23 | expr ">=" expr + 24 | expr '<' expr + 25 | expr "<=" expr - 24 expr: expr '-' expr - 25 | expr '+' expr - 26 | expr '*' expr - 27 | expr '/' expr - 28 | expr '%' expr - 29 | '-' expr - 30 | '(' expr ')' - 31 | value - 32 | "ival" - 33 | "rand" '(' expr ')' + 26 expr: expr '-' expr + 27 | expr '+' expr + 28 | expr '*' expr + 29 | expr '/' expr + 30 | expr '%' expr + 31 | '-' expr + 32 | '(' expr ')' + 33 | value + 34 | "ival" + 35 | "rand" '(' expr ')' - 34 value: "identifier" + 36 value: "identifier" - 35 args: expr - 36 | args ',' expr + 37 args: expr + 38 | args ',' expr -出現位置の規則による終端 +Terminals, with rules where they appear "end of file" (0) 0 -'%' (37) 28 -'(' (40) 30 33 -')' (41) 30 33 -'*' (42) 26 -'+' (43) 25 -',' (44) 36 -'-' (45) 24 29 -'/' (47) 27 -'<' (60) 22 -'=' (61) 17 -'>' (62) 20 -error (256) 16 -"ival" (258) 32 -"identifier" (259) 34 -"==" (260) 18 -"!=" (261) 19 -">=" (262) 21 -"<=" (263) 23 +'%' (37) 30 +'(' (40) 32 35 +')' (41) 32 35 +'*' (42) 28 +'+' (43) 27 +',' (44) 38 +'-' (45) 26 31 +'/' (47) 29 +'<' (60) 24 +'=' (61) 19 +'>' (62) 22 +error (256) 18 +"ival" (258) 34 +"identifier" (259) 16 17 36 +"==" (260) 20 +"!=" (261) 21 +">=" (262) 23 +"<=" (263) 25 "\n" (264) 3 4 "if" (265) 7 "then" (266) 7 @@ -79,36 +81,38 @@ "while" (272) 13 "wend" (273) 14 "end" (274) 5 -"rand" (275) 33 +"rand" (275) 35 "print" (276) 15 -NEG (277) -"step" (278) 10 +":" (277) 16 +"goto" (278) 17 +NEG (279) +"step" (280) 10 -出現位置の規則による非終端 +Nonterminals, with rules where they appear -$accept (35) - 左辺: 0 -unit (36) - 左辺: 1 2, 右辺: 0 2 -states (37) - 左辺: 3 4, 右辺: 1 2 -statement (38) - 左辺: 5 6 7 8 9 10 11 12 13 14 15 16, 右辺: 3 -assign (39) - 左辺: 17, 右辺: 6 10 11 -comp_expr (40) - 左辺: 18 19 20 21 22 23, 右辺: 7 13 -expr (41) - 左辺: 24 25 26 27 28 29 30 31 32 33, 右辺: 10 11 17 18 19 20 - 21 22 23 24 25 26 27 28 29 30 33 35 36 -value (42) - 左辺: 34, 右辺: 17 31 -args (43) - 左辺: 35 36, 右辺: 15 36 +$accept (37) + on left: 0 +unit (38) + on left: 1 2, on right: 0 2 +states (39) + on left: 3 4, on right: 1 2 +statement (40) + on left: 5 6 7 8 9 10 11 12 13 14 15 16 17 18, on right: 3 +assign (41) + on left: 19, on right: 6 10 11 +comp_expr (42) + on left: 20 21 22 23 24 25, on right: 7 13 +expr (43) + on left: 26 27 28 29 30 31 32 33 34 35, on right: 10 11 19 20 21 + 22 23 24 25 26 27 28 29 30 31 32 35 37 38 +value (44) + on left: 36, on right: 19 33 +args (45) + on left: 37 38, on right: 15 38 -状態 0 +state 0 0 $accept: . unit "end of file" 1 unit: . states @@ -126,9 +130,11 @@ 13 | . "while" comp_expr 14 | . "wend" 15 | . "print" args - 16 | . error - 17 assign: . value '=' expr - 34 value: . "identifier" + 16 | . "identifier" ":" + 17 | . "goto" "identifier" + 18 | . error + 19 assign: . value '=' expr + 36 value: . "identifier" error shift, and go to state 1 "identifier" shift, and go to state 2 @@ -142,176 +148,187 @@ "wend" shift, and go to state 10 "end" shift, and go to state 11 "print" shift, and go to state 12 + "goto" shift, and go to state 13 - unit go to state 13 - states go to state 14 - statement go to state 15 - assign go to state 16 - value go to state 17 + unit go to state 14 + states go to state 15 + statement go to state 16 + assign go to state 17 + value go to state 18 -状態 1 +state 1 - 16 statement: error . + 18 statement: error . - $default reduce using rule 16 (statement) + $default reduce using rule 18 (statement) -状態 2 +state 2 - 34 value: "identifier" . + 16 statement: "identifier" . ":" + 36 value: "identifier" . ['='] - $default reduce using rule 34 (value) + ":" shift, and go to state 19 + + $default reduce using rule 36 (value) -状態 3 +state 3 4 states: "\n" . $default reduce using rule 4 (states) -状態 4 +state 4 7 statement: "if" . comp_expr "then" - 18 comp_expr: . expr "==" expr - 19 | . expr "!=" expr - 20 | . expr '>' expr - 21 | . expr ">=" expr - 22 | . expr '<' expr - 23 | . expr "<=" expr - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" + 20 comp_expr: . expr "==" expr + 21 | . expr "!=" expr + 22 | . expr '>' expr + 23 | . expr ">=" expr + 24 | . expr '<' expr + 25 | . expr "<=" expr + 26 expr: . expr '-' expr + 27 | . expr '+' expr + 28 | . expr '*' expr + 29 | . expr '/' expr + 30 | . expr '%' expr + 31 | . '-' expr + 32 | . '(' expr ')' + 33 | . value + 34 | . "ival" + 35 | . "rand" '(' expr ')' + 36 value: . "identifier" - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 + "ival" shift, and go to state 20 + "identifier" shift, and go to state 21 + "rand" shift, and go to state 22 + '-' shift, and go to state 23 + '(' shift, and go to state 24 - comp_expr go to state 22 - expr go to state 23 - value go to state 24 + comp_expr go to state 25 + expr go to state 26 + value go to state 27 -状態 5 +state 5 8 statement: "else" . $default reduce using rule 8 (statement) -状態 6 +state 6 9 statement: "endif" . $default reduce using rule 9 (statement) -状態 7 +state 7 10 statement: "for" . assign "to" expr "step" expr 11 | "for" . assign "to" expr - 17 assign: . value '=' expr - 34 value: . "identifier" + 19 assign: . value '=' expr + 36 value: . "identifier" - "identifier" shift, and go to state 2 + "identifier" shift, and go to state 21 - assign go to state 25 - value go to state 17 + assign go to state 28 + value go to state 18 -状態 8 +state 8 12 statement: "next" . $default reduce using rule 12 (statement) -状態 9 +state 9 13 statement: "while" . comp_expr - 18 comp_expr: . expr "==" expr - 19 | . expr "!=" expr - 20 | . expr '>' expr - 21 | . expr ">=" expr - 22 | . expr '<' expr - 23 | . expr "<=" expr - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" + 20 comp_expr: . expr "==" expr + 21 | . expr "!=" expr + 22 | . expr '>' expr + 23 | . expr ">=" expr + 24 | . expr '<' expr + 25 | . expr "<=" expr + 26 expr: . expr '-' expr + 27 | . expr '+' expr + 28 | . expr '*' expr + 29 | . expr '/' expr + 30 | . expr '%' expr + 31 | . '-' expr + 32 | . '(' expr ')' + 33 | . value + 34 | . "ival" + 35 | . "rand" '(' expr ')' + 36 value: . "identifier" - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 + "ival" shift, and go to state 20 + "identifier" shift, and go to state 21 + "rand" shift, and go to state 22 + '-' shift, and go to state 23 + '(' shift, and go to state 24 - comp_expr go to state 26 - expr go to state 23 - value go to state 24 + comp_expr go to state 29 + expr go to state 26 + value go to state 27 -状態 10 +state 10 14 statement: "wend" . $default reduce using rule 14 (statement) -状態 11 +state 11 5 statement: "end" . $default reduce using rule 5 (statement) -状態 12 +state 12 15 statement: "print" . args - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" - 35 args: . expr - 36 | . args ',' expr + 26 expr: . expr '-' expr + 27 | . expr '+' expr + 28 | . expr '*' expr + 29 | . expr '/' expr + 30 | . expr '%' expr + 31 | . '-' expr + 32 | . '(' expr ')' + 33 | . value + 34 | . "ival" + 35 | . "rand" '(' expr ')' + 36 value: . "identifier" + 37 args: . expr + 38 | . args ',' expr - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 + "ival" shift, and go to state 20 + "identifier" shift, and go to state 21 + "rand" shift, and go to state 22 + '-' shift, and go to state 23 + '(' shift, and go to state 24 - expr go to state 27 - value go to state 24 - args go to state 28 + expr go to state 30 + value go to state 27 + args go to state 31 -状態 13 +state 13 + + 17 statement: "goto" . "identifier" + + "identifier" shift, and go to state 32 + + +state 14 0 $accept: unit . "end of file" 2 unit: unit . states @@ -328,11 +345,13 @@ 13 | . "while" comp_expr 14 | . "wend" 15 | . "print" args - 16 | . error - 17 assign: . value '=' expr - 34 value: . "identifier" + 16 | . "identifier" ":" + 17 | . "goto" "identifier" + 18 | . error + 19 assign: . value '=' expr + 36 value: . "identifier" - "end of file" shift, and go to state 29 + "end of file" shift, and go to state 33 error shift, and go to state 1 "identifier" shift, and go to state 2 "\n" shift, and go to state 3 @@ -345,959 +364,981 @@ "wend" shift, and go to state 10 "end" shift, and go to state 11 "print" shift, and go to state 12 + "goto" shift, and go to state 13 - states go to state 30 - statement go to state 15 - assign go to state 16 - value go to state 17 + states go to state 34 + statement go to state 16 + assign go to state 17 + value go to state 18 -状態 14 +state 15 1 unit: states . $default reduce using rule 1 (unit) -状態 15 +state 16 3 states: statement . "\n" - "\n" shift, and go to state 31 + "\n" shift, and go to state 35 -状態 16 +state 17 6 statement: assign . $default reduce using rule 6 (statement) -状態 17 +state 18 + + 19 assign: value . '=' expr + + '=' shift, and go to state 36 - 17 assign: value . '=' expr + +state 19 - '=' shift, and go to state 32 + 16 statement: "identifier" ":" . + + $default reduce using rule 16 (statement) -状態 18 +state 20 - 32 expr: "ival" . + 34 expr: "ival" . - $default reduce using rule 32 (expr) + $default reduce using rule 34 (expr) -状態 19 +state 21 + + 36 value: "identifier" . + + $default reduce using rule 36 (value) - 33 expr: "rand" . '(' expr ')' + +state 22 - '(' shift, and go to state 33 + 35 expr: "rand" . '(' expr ')' + + '(' shift, and go to state 37 -状態 20 +state 23 - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 29 | '-' . expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" + 26 expr: . expr '-' expr + 27 | . expr '+' expr + 28 | . expr '*' expr + 29 | . expr '/' expr + 30 | . expr '%' expr + 31 | . '-' expr + 31 | '-' . expr + 32 | . '(' expr ')' + 33 | . value + 34 | . "ival" + 35 | . "rand" '(' expr ')' + 36 value: . "identifier" - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 + "ival" shift, and go to state 20 + "identifier" shift, and go to state 21 + "rand" shift, and go to state 22 + '-' shift, and go to state 23 + '(' shift, and go to state 24 - expr go to state 34 - value go to state 24 + expr go to state 38 + value go to state 27 -状態 21 +state 24 - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 30 | '(' . expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" + 26 expr: . expr '-' expr + 27 | . expr '+' expr + 28 | . expr '*' expr + 29 | . expr '/' expr + 30 | . expr '%' expr + 31 | . '-' expr + 32 | . '(' expr ')' + 32 | '(' . expr ')' + 33 | . value + 34 | . "ival" + 35 | . "rand" '(' expr ')' + 36 value: . "identifier" - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 + "ival" shift, and go to state 20 + "identifier" shift, and go to state 21 + "rand" shift, and go to state 22 + '-' shift, and go to state 23 + '(' shift, and go to state 24 - expr go to state 35 - value go to state 24 + expr go to state 39 + value go to state 27 -状態 22 +state 25 7 statement: "if" comp_expr . "then" - "then" shift, and go to state 36 + "then" shift, and go to state 40 -状態 23 +state 26 - 18 comp_expr: expr . "==" expr - 19 | expr . "!=" expr - 20 | expr . '>' expr - 21 | expr . ">=" expr - 22 | expr . '<' expr - 23 | expr . "<=" expr - 24 expr: expr . '-' expr - 25 | expr . '+' expr - 26 | expr . '*' expr - 27 | expr . '/' expr - 28 | expr . '%' expr + 20 comp_expr: expr . "==" expr + 21 | expr . "!=" expr + 22 | expr . '>' expr + 23 | expr . ">=" expr + 24 | expr . '<' expr + 25 | expr . "<=" expr + 26 expr: expr . '-' expr + 27 | expr . '+' expr + 28 | expr . '*' expr + 29 | expr . '/' expr + 30 | expr . '%' expr - "==" shift, and go to state 37 - "!=" shift, and go to state 38 - ">=" shift, and go to state 39 - "<=" shift, and go to state 40 - '+' shift, and go to state 41 - '-' shift, and go to state 42 - '*' shift, and go to state 43 - '/' shift, and go to state 44 - '%' shift, and go to state 45 - '>' shift, and go to state 46 - '<' shift, and go to state 47 + "==" shift, and go to state 41 + "!=" shift, and go to state 42 + ">=" shift, and go to state 43 + "<=" shift, and go to state 44 + '+' shift, and go to state 45 + '-' shift, and go to state 46 + '*' shift, and go to state 47 + '/' shift, and go to state 48 + '%' shift, and go to state 49 + '>' shift, and go to state 50 + '<' shift, and go to state 51 -状態 24 +state 27 - 31 expr: value . + 33 expr: value . - $default reduce using rule 31 (expr) + $default reduce using rule 33 (expr) -状態 25 +state 28 10 statement: "for" assign . "to" expr "step" expr 11 | "for" assign . "to" expr - "to" shift, and go to state 48 + "to" shift, and go to state 52 -状態 26 +state 29 13 statement: "while" comp_expr . $default reduce using rule 13 (statement) -状態 27 +state 30 - 24 expr: expr . '-' expr - 25 | expr . '+' expr - 26 | expr . '*' expr - 27 | expr . '/' expr - 28 | expr . '%' expr - 35 args: expr . ["\n", ','] + 26 expr: expr . '-' expr + 27 | expr . '+' expr + 28 | expr . '*' expr + 29 | expr . '/' expr + 30 | expr . '%' expr + 37 args: expr . ["\n", ','] - '+' shift, and go to state 41 - '-' shift, and go to state 42 - '*' shift, and go to state 43 - '/' shift, and go to state 44 - '%' shift, and go to state 45 + '+' shift, and go to state 45 + '-' shift, and go to state 46 + '*' shift, and go to state 47 + '/' shift, and go to state 48 + '%' shift, and go to state 49 - $default reduce using rule 35 (args) + $default reduce using rule 37 (args) -状態 28 +state 31 15 statement: "print" args . ["\n"] - 36 args: args . ',' expr + 38 args: args . ',' expr - ',' shift, and go to state 49 + ',' shift, and go to state 53 $default reduce using rule 15 (statement) -状態 29 +state 32 + + 17 statement: "goto" "identifier" . + + $default reduce using rule 17 (statement) + + +state 33 0 $accept: unit "end of file" . $default accept -状態 30 +state 34 2 unit: unit states . $default reduce using rule 2 (unit) -状態 31 +state 35 3 states: statement "\n" . $default reduce using rule 3 (states) -状態 32 +state 36 - 17 assign: value '=' . expr - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" + 19 assign: value '=' . expr + 26 expr: . expr '-' expr + 27 | . expr '+' expr + 28 | . expr '*' expr + 29 | . expr '/' expr + 30 | . expr '%' expr + 31 | . '-' expr + 32 | . '(' expr ')' + 33 | . value + 34 | . "ival" + 35 | . "rand" '(' expr ')' + 36 value: . "identifier" - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 + "ival" shift, and go to state 20 + "identifier" shift, and go to state 21 + "rand" shift, and go to state 22 + '-' shift, and go to state 23 + '(' shift, and go to state 24 - expr go to state 50 - value go to state 24 + expr go to state 54 + value go to state 27 -状態 33 +state 37 - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 33 | "rand" '(' . expr ')' - 34 value: . "identifier" + 26 expr: . expr '-' expr + 27 | . expr '+' expr + 28 | . expr '*' expr + 29 | . expr '/' expr + 30 | . expr '%' expr + 31 | . '-' expr + 32 | . '(' expr ')' + 33 | . value + 34 | . "ival" + 35 | . "rand" '(' expr ')' + 35 | "rand" '(' . expr ')' + 36 value: . "identifier" - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 + "ival" shift, and go to state 20 + "identifier" shift, and go to state 21 + "rand" shift, and go to state 22 + '-' shift, and go to state 23 + '(' shift, and go to state 24 - expr go to state 51 - value go to state 24 + expr go to state 55 + value go to state 27 -状態 34 +state 38 - 24 expr: expr . '-' expr - 25 | expr . '+' expr - 26 | expr . '*' expr - 27 | expr . '/' expr - 28 | expr . '%' expr - 29 | '-' expr . ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', '*', '/', '%', "step", '>', '<', ')', ','] + 26 expr: expr . '-' expr + 27 | expr . '+' expr + 28 | expr . '*' expr + 29 | expr . '/' expr + 30 | expr . '%' expr + 31 | '-' expr . ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', '*', '/', '%', "step", '>', '<', ')', ','] - $default reduce using rule 29 (expr) + $default reduce using rule 31 (expr) - Conflict between rule 29 and token '+' resolved as reduce ('+' < NEG). - Conflict between rule 29 and token '-' resolved as reduce ('-' < NEG). - Conflict between rule 29 and token '*' resolved as reduce ('*' < NEG). - Conflict between rule 29 and token '/' resolved as reduce ('/' < NEG). - Conflict between rule 29 and token '%' resolved as reduce ('%' < NEG). + Conflict between rule 31 and token '+' resolved as reduce ('+' < NEG). + Conflict between rule 31 and token '-' resolved as reduce ('-' < NEG). + Conflict between rule 31 and token '*' resolved as reduce ('*' < NEG). + Conflict between rule 31 and token '/' resolved as reduce ('/' < NEG). + Conflict between rule 31 and token '%' resolved as reduce ('%' < NEG). -状態 35 +state 39 - 24 expr: expr . '-' expr - 25 | expr . '+' expr - 26 | expr . '*' expr - 27 | expr . '/' expr - 28 | expr . '%' expr - 30 | '(' expr . ')' + 26 expr: expr . '-' expr + 27 | expr . '+' expr + 28 | expr . '*' expr + 29 | expr . '/' expr + 30 | expr . '%' expr + 32 | '(' expr . ')' - '+' shift, and go to state 41 - '-' shift, and go to state 42 - '*' shift, and go to state 43 - '/' shift, and go to state 44 - '%' shift, and go to state 45 - ')' shift, and go to state 52 + '+' shift, and go to state 45 + '-' shift, and go to state 46 + '*' shift, and go to state 47 + '/' shift, and go to state 48 + '%' shift, and go to state 49 + ')' shift, and go to state 56 -状態 36 +state 40 7 statement: "if" comp_expr "then" . $default reduce using rule 7 (statement) -状態 37 +state 41 - 18 comp_expr: expr "==" . expr - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" + 20 comp_expr: expr "==" . expr + 26 expr: . expr '-' expr + 27 | . expr '+' expr + 28 | . expr '*' expr + 29 | . expr '/' expr + 30 | . expr '%' expr + 31 | . '-' expr + 32 | . '(' expr ')' + 33 | . value + 34 | . "ival" + 35 | . "rand" '(' expr ')' + 36 value: . "identifier" - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 + "ival" shift, and go to state 20 + "identifier" shift, and go to state 21 + "rand" shift, and go to state 22 + '-' shift, and go to state 23 + '(' shift, and go to state 24 - expr go to state 53 - value go to state 24 + expr go to state 57 + value go to state 27 -状態 38 +state 42 - 19 comp_expr: expr "!=" . expr - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" + 21 comp_expr: expr "!=" . expr + 26 expr: . expr '-' expr + 27 | . expr '+' expr + 28 | . expr '*' expr + 29 | . expr '/' expr + 30 | . expr '%' expr + 31 | . '-' expr + 32 | . '(' expr ')' + 33 | . value + 34 | . "ival" + 35 | . "rand" '(' expr ')' + 36 value: . "identifier" - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 + "ival" shift, and go to state 20 + "identifier" shift, and go to state 21 + "rand" shift, and go to state 22 + '-' shift, and go to state 23 + '(' shift, and go to state 24 - expr go to state 54 - value go to state 24 + expr go to state 58 + value go to state 27 -状態 39 +state 43 - 21 comp_expr: expr ">=" . expr - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" + 23 comp_expr: expr ">=" . expr + 26 expr: . expr '-' expr + 27 | . expr '+' expr + 28 | . expr '*' expr + 29 | . expr '/' expr + 30 | . expr '%' expr + 31 | . '-' expr + 32 | . '(' expr ')' + 33 | . value + 34 | . "ival" + 35 | . "rand" '(' expr ')' + 36 value: . "identifier" - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 + "ival" shift, and go to state 20 + "identifier" shift, and go to state 21 + "rand" shift, and go to state 22 + '-' shift, and go to state 23 + '(' shift, and go to state 24 - expr go to state 55 - value go to state 24 + expr go to state 59 + value go to state 27 -状態 40 +state 44 - 23 comp_expr: expr "<=" . expr - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" + 25 comp_expr: expr "<=" . expr + 26 expr: . expr '-' expr + 27 | . expr '+' expr + 28 | . expr '*' expr + 29 | . expr '/' expr + 30 | . expr '%' expr + 31 | . '-' expr + 32 | . '(' expr ')' + 33 | . value + 34 | . "ival" + 35 | . "rand" '(' expr ')' + 36 value: . "identifier" - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 + "ival" shift, and go to state 20 + "identifier" shift, and go to state 21 + "rand" shift, and go to state 22 + '-' shift, and go to state 23 + '(' shift, and go to state 24 - expr go to state 56 - value go to state 24 + expr go to state 60 + value go to state 27 -状態 41 +state 45 - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 25 | expr '+' . expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" + 26 expr: . expr '-' expr + 27 | . expr '+' expr + 27 | expr '+' . expr + 28 | . expr '*' expr + 29 | . expr '/' expr + 30 | . expr '%' expr + 31 | . '-' expr + 32 | . '(' expr ')' + 33 | . value + 34 | . "ival" + 35 | . "rand" '(' expr ')' + 36 value: . "identifier" - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 + "ival" shift, and go to state 20 + "identifier" shift, and go to state 21 + "rand" shift, and go to state 22 + '-' shift, and go to state 23 + '(' shift, and go to state 24 - expr go to state 57 - value go to state 24 + expr go to state 61 + value go to state 27 -状態 42 +state 46 - 24 expr: . expr '-' expr - 24 | expr '-' . expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" + 26 expr: . expr '-' expr + 26 | expr '-' . expr + 27 | . expr '+' expr + 28 | . expr '*' expr + 29 | . expr '/' expr + 30 | . expr '%' expr + 31 | . '-' expr + 32 | . '(' expr ')' + 33 | . value + 34 | . "ival" + 35 | . "rand" '(' expr ')' + 36 value: . "identifier" - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 + "ival" shift, and go to state 20 + "identifier" shift, and go to state 21 + "rand" shift, and go to state 22 + '-' shift, and go to state 23 + '(' shift, and go to state 24 - expr go to state 58 - value go to state 24 + expr go to state 62 + value go to state 27 -状態 43 +state 47 - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 26 | expr '*' . expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" + 26 expr: . expr '-' expr + 27 | . expr '+' expr + 28 | . expr '*' expr + 28 | expr '*' . expr + 29 | . expr '/' expr + 30 | . expr '%' expr + 31 | . '-' expr + 32 | . '(' expr ')' + 33 | . value + 34 | . "ival" + 35 | . "rand" '(' expr ')' + 36 value: . "identifier" - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 + "ival" shift, and go to state 20 + "identifier" shift, and go to state 21 + "rand" shift, and go to state 22 + '-' shift, and go to state 23 + '(' shift, and go to state 24 - expr go to state 59 - value go to state 24 + expr go to state 63 + value go to state 27 -状態 44 +state 48 - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 27 | expr '/' . expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" + 26 expr: . expr '-' expr + 27 | . expr '+' expr + 28 | . expr '*' expr + 29 | . expr '/' expr + 29 | expr '/' . expr + 30 | . expr '%' expr + 31 | . '-' expr + 32 | . '(' expr ')' + 33 | . value + 34 | . "ival" + 35 | . "rand" '(' expr ')' + 36 value: . "identifier" - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 + "ival" shift, and go to state 20 + "identifier" shift, and go to state 21 + "rand" shift, and go to state 22 + '-' shift, and go to state 23 + '(' shift, and go to state 24 - expr go to state 60 - value go to state 24 + expr go to state 64 + value go to state 27 -状態 45 +state 49 - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 28 | expr '%' . expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" + 26 expr: . expr '-' expr + 27 | . expr '+' expr + 28 | . expr '*' expr + 29 | . expr '/' expr + 30 | . expr '%' expr + 30 | expr '%' . expr + 31 | . '-' expr + 32 | . '(' expr ')' + 33 | . value + 34 | . "ival" + 35 | . "rand" '(' expr ')' + 36 value: . "identifier" - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 + "ival" shift, and go to state 20 + "identifier" shift, and go to state 21 + "rand" shift, and go to state 22 + '-' shift, and go to state 23 + '(' shift, and go to state 24 - expr go to state 61 - value go to state 24 + expr go to state 65 + value go to state 27 -状態 46 +state 50 - 20 comp_expr: expr '>' . expr - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" + 22 comp_expr: expr '>' . expr + 26 expr: . expr '-' expr + 27 | . expr '+' expr + 28 | . expr '*' expr + 29 | . expr '/' expr + 30 | . expr '%' expr + 31 | . '-' expr + 32 | . '(' expr ')' + 33 | . value + 34 | . "ival" + 35 | . "rand" '(' expr ')' + 36 value: . "identifier" - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 + "ival" shift, and go to state 20 + "identifier" shift, and go to state 21 + "rand" shift, and go to state 22 + '-' shift, and go to state 23 + '(' shift, and go to state 24 - expr go to state 62 - value go to state 24 + expr go to state 66 + value go to state 27 -状態 47 +state 51 - 22 comp_expr: expr '<' . expr - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" + 24 comp_expr: expr '<' . expr + 26 expr: . expr '-' expr + 27 | . expr '+' expr + 28 | . expr '*' expr + 29 | . expr '/' expr + 30 | . expr '%' expr + 31 | . '-' expr + 32 | . '(' expr ')' + 33 | . value + 34 | . "ival" + 35 | . "rand" '(' expr ')' + 36 value: . "identifier" - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 + "ival" shift, and go to state 20 + "identifier" shift, and go to state 21 + "rand" shift, and go to state 22 + '-' shift, and go to state 23 + '(' shift, and go to state 24 - expr go to state 63 - value go to state 24 + expr go to state 67 + value go to state 27 -状態 48 +state 52 10 statement: "for" assign "to" . expr "step" expr 11 | "for" assign "to" . expr - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" + 26 expr: . expr '-' expr + 27 | . expr '+' expr + 28 | . expr '*' expr + 29 | . expr '/' expr + 30 | . expr '%' expr + 31 | . '-' expr + 32 | . '(' expr ')' + 33 | . value + 34 | . "ival" + 35 | . "rand" '(' expr ')' + 36 value: . "identifier" - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 + "ival" shift, and go to state 20 + "identifier" shift, and go to state 21 + "rand" shift, and go to state 22 + '-' shift, and go to state 23 + '(' shift, and go to state 24 - expr go to state 64 - value go to state 24 + expr go to state 68 + value go to state 27 -状態 49 - - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" - 36 args: args ',' . expr - - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 +state 53 - expr go to state 65 - value go to state 24 - - -状態 50 + 26 expr: . expr '-' expr + 27 | . expr '+' expr + 28 | . expr '*' expr + 29 | . expr '/' expr + 30 | . expr '%' expr + 31 | . '-' expr + 32 | . '(' expr ')' + 33 | . value + 34 | . "ival" + 35 | . "rand" '(' expr ')' + 36 value: . "identifier" + 38 args: args ',' . expr - 17 assign: value '=' expr . ["\n", "to"] - 24 expr: expr . '-' expr - 25 | expr . '+' expr - 26 | expr . '*' expr - 27 | expr . '/' expr - 28 | expr . '%' expr + "ival" shift, and go to state 20 + "identifier" shift, and go to state 21 + "rand" shift, and go to state 22 + '-' shift, and go to state 23 + '(' shift, and go to state 24 - '+' shift, and go to state 41 - '-' shift, and go to state 42 - '*' shift, and go to state 43 - '/' shift, and go to state 44 - '%' shift, and go to state 45 - - $default reduce using rule 17 (assign) + expr go to state 69 + value go to state 27 -状態 51 +state 54 - 24 expr: expr . '-' expr - 25 | expr . '+' expr - 26 | expr . '*' expr - 27 | expr . '/' expr - 28 | expr . '%' expr - 33 | "rand" '(' expr . ')' + 19 assign: value '=' expr . ["\n", "to"] + 26 expr: expr . '-' expr + 27 | expr . '+' expr + 28 | expr . '*' expr + 29 | expr . '/' expr + 30 | expr . '%' expr - '+' shift, and go to state 41 - '-' shift, and go to state 42 - '*' shift, and go to state 43 - '/' shift, and go to state 44 - '%' shift, and go to state 45 - ')' shift, and go to state 66 + '+' shift, and go to state 45 + '-' shift, and go to state 46 + '*' shift, and go to state 47 + '/' shift, and go to state 48 + '%' shift, and go to state 49 + + $default reduce using rule 19 (assign) -状態 52 +state 55 - 30 expr: '(' expr ')' . + 26 expr: expr . '-' expr + 27 | expr . '+' expr + 28 | expr . '*' expr + 29 | expr . '/' expr + 30 | expr . '%' expr + 35 | "rand" '(' expr . ')' - $default reduce using rule 30 (expr) + '+' shift, and go to state 45 + '-' shift, and go to state 46 + '*' shift, and go to state 47 + '/' shift, and go to state 48 + '%' shift, and go to state 49 + ')' shift, and go to state 70 -状態 53 +state 56 - 18 comp_expr: expr "==" expr . ["\n", "then"] - 24 expr: expr . '-' expr - 25 | expr . '+' expr - 26 | expr . '*' expr - 27 | expr . '/' expr - 28 | expr . '%' expr + 32 expr: '(' expr ')' . - '+' shift, and go to state 41 - '-' shift, and go to state 42 - '*' shift, and go to state 43 - '/' shift, and go to state 44 - '%' shift, and go to state 45 - - $default reduce using rule 18 (comp_expr) + $default reduce using rule 32 (expr) -状態 54 +state 57 - 19 comp_expr: expr "!=" expr . ["\n", "then"] - 24 expr: expr . '-' expr - 25 | expr . '+' expr - 26 | expr . '*' expr - 27 | expr . '/' expr - 28 | expr . '%' expr + 20 comp_expr: expr "==" expr . ["\n", "then"] + 26 expr: expr . '-' expr + 27 | expr . '+' expr + 28 | expr . '*' expr + 29 | expr . '/' expr + 30 | expr . '%' expr - '+' shift, and go to state 41 - '-' shift, and go to state 42 - '*' shift, and go to state 43 - '/' shift, and go to state 44 - '%' shift, and go to state 45 + '+' shift, and go to state 45 + '-' shift, and go to state 46 + '*' shift, and go to state 47 + '/' shift, and go to state 48 + '%' shift, and go to state 49 - $default reduce using rule 19 (comp_expr) + $default reduce using rule 20 (comp_expr) -状態 55 +state 58 - 21 comp_expr: expr ">=" expr . ["\n", "then"] - 24 expr: expr . '-' expr - 25 | expr . '+' expr - 26 | expr . '*' expr - 27 | expr . '/' expr - 28 | expr . '%' expr + 21 comp_expr: expr "!=" expr . ["\n", "then"] + 26 expr: expr . '-' expr + 27 | expr . '+' expr + 28 | expr . '*' expr + 29 | expr . '/' expr + 30 | expr . '%' expr - '+' shift, and go to state 41 - '-' shift, and go to state 42 - '*' shift, and go to state 43 - '/' shift, and go to state 44 - '%' shift, and go to state 45 + '+' shift, and go to state 45 + '-' shift, and go to state 46 + '*' shift, and go to state 47 + '/' shift, and go to state 48 + '%' shift, and go to state 49 $default reduce using rule 21 (comp_expr) -状態 56 +state 59 - 23 comp_expr: expr "<=" expr . ["\n", "then"] - 24 expr: expr . '-' expr - 25 | expr . '+' expr - 26 | expr . '*' expr - 27 | expr . '/' expr - 28 | expr . '%' expr + 23 comp_expr: expr ">=" expr . ["\n", "then"] + 26 expr: expr . '-' expr + 27 | expr . '+' expr + 28 | expr . '*' expr + 29 | expr . '/' expr + 30 | expr . '%' expr - '+' shift, and go to state 41 - '-' shift, and go to state 42 - '*' shift, and go to state 43 - '/' shift, and go to state 44 - '%' shift, and go to state 45 + '+' shift, and go to state 45 + '-' shift, and go to state 46 + '*' shift, and go to state 47 + '/' shift, and go to state 48 + '%' shift, and go to state 49 $default reduce using rule 23 (comp_expr) -状態 57 - - 24 expr: expr . '-' expr - 25 | expr . '+' expr ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', "step", '>', '<', ')', ','] - 25 | expr '+' expr . ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', "step", '>', '<', ')', ','] - 26 | expr . '*' expr - 27 | expr . '/' expr - 28 | expr . '%' expr +state 60 - '*' shift, and go to state 43 - '/' shift, and go to state 44 - '%' shift, and go to state 45 - - $default reduce using rule 25 (expr) + 25 comp_expr: expr "<=" expr . ["\n", "then"] + 26 expr: expr . '-' expr + 27 | expr . '+' expr + 28 | expr . '*' expr + 29 | expr . '/' expr + 30 | expr . '%' expr - Conflict between rule 25 and token '+' resolved as reduce (%left '+'). - Conflict between rule 25 and token '-' resolved as reduce (%left '-'). - Conflict between rule 25 and token '*' resolved as shift ('+' < '*'). - Conflict between rule 25 and token '/' resolved as shift ('+' < '/'). - Conflict between rule 25 and token '%' resolved as shift ('+' < '%'). + '+' shift, and go to state 45 + '-' shift, and go to state 46 + '*' shift, and go to state 47 + '/' shift, and go to state 48 + '%' shift, and go to state 49 + + $default reduce using rule 25 (comp_expr) -状態 58 +state 61 - 24 expr: expr . '-' expr ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', "step", '>', '<', ')', ','] - 24 | expr '-' expr . ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', "step", '>', '<', ')', ','] - 25 | expr . '+' expr - 26 | expr . '*' expr - 27 | expr . '/' expr - 28 | expr . '%' expr + 26 expr: expr . '-' expr + 27 | expr . '+' expr ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', "step", '>', '<', ')', ','] + 27 | expr '+' expr . ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', "step", '>', '<', ')', ','] + 28 | expr . '*' expr + 29 | expr . '/' expr + 30 | expr . '%' expr - '*' shift, and go to state 43 - '/' shift, and go to state 44 - '%' shift, and go to state 45 + '*' shift, and go to state 47 + '/' shift, and go to state 48 + '%' shift, and go to state 49 - $default reduce using rule 24 (expr) + $default reduce using rule 27 (expr) - Conflict between rule 24 and token '+' resolved as reduce (%left '+'). - Conflict between rule 24 and token '-' resolved as reduce (%left '-'). - Conflict between rule 24 and token '*' resolved as shift ('-' < '*'). - Conflict between rule 24 and token '/' resolved as shift ('-' < '/'). - Conflict between rule 24 and token '%' resolved as shift ('-' < '%'). + Conflict between rule 27 and token '+' resolved as reduce (%left '+'). + Conflict between rule 27 and token '-' resolved as reduce (%left '-'). + Conflict between rule 27 and token '*' resolved as shift ('+' < '*'). + Conflict between rule 27 and token '/' resolved as shift ('+' < '/'). + Conflict between rule 27 and token '%' resolved as shift ('+' < '%'). -状態 59 +state 62 - 24 expr: expr . '-' expr - 25 | expr . '+' expr - 26 | expr . '*' expr ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', '*', '/', '%', "step", '>', '<', ')', ','] - 26 | expr '*' expr . ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', '*', '/', '%', "step", '>', '<', ')', ','] - 27 | expr . '/' expr - 28 | expr . '%' expr + 26 expr: expr . '-' expr ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', "step", '>', '<', ')', ','] + 26 | expr '-' expr . ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', "step", '>', '<', ')', ','] + 27 | expr . '+' expr + 28 | expr . '*' expr + 29 | expr . '/' expr + 30 | expr . '%' expr + + '*' shift, and go to state 47 + '/' shift, and go to state 48 + '%' shift, and go to state 49 $default reduce using rule 26 (expr) - Conflict between rule 26 and token '+' resolved as reduce ('+' < '*'). - Conflict between rule 26 and token '-' resolved as reduce ('-' < '*'). - Conflict between rule 26 and token '*' resolved as reduce (%left '*'). - Conflict between rule 26 and token '/' resolved as reduce (%left '/'). - Conflict between rule 26 and token '%' resolved as reduce (%left '%'). + Conflict between rule 26 and token '+' resolved as reduce (%left '+'). + Conflict between rule 26 and token '-' resolved as reduce (%left '-'). + Conflict between rule 26 and token '*' resolved as shift ('-' < '*'). + Conflict between rule 26 and token '/' resolved as shift ('-' < '/'). + Conflict between rule 26 and token '%' resolved as shift ('-' < '%'). -状態 60 - - 24 expr: expr . '-' expr - 25 | expr . '+' expr - 26 | expr . '*' expr - 27 | expr . '/' expr ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', '*', '/', '%', "step", '>', '<', ')', ','] - 27 | expr '/' expr . ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', '*', '/', '%', "step", '>', '<', ')', ','] - 28 | expr . '%' expr - - $default reduce using rule 27 (expr) +state 63 - Conflict between rule 27 and token '+' resolved as reduce ('+' < '/'). - Conflict between rule 27 and token '-' resolved as reduce ('-' < '/'). - Conflict between rule 27 and token '*' resolved as reduce (%left '*'). - Conflict between rule 27 and token '/' resolved as reduce (%left '/'). - Conflict between rule 27 and token '%' resolved as reduce (%left '%'). - - -状態 61 - - 24 expr: expr . '-' expr - 25 | expr . '+' expr - 26 | expr . '*' expr - 27 | expr . '/' expr - 28 | expr . '%' expr ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', '*', '/', '%', "step", '>', '<', ')', ','] - 28 | expr '%' expr . ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', '*', '/', '%', "step", '>', '<', ')', ','] + 26 expr: expr . '-' expr + 27 | expr . '+' expr + 28 | expr . '*' expr ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', '*', '/', '%', "step", '>', '<', ')', ','] + 28 | expr '*' expr . ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', '*', '/', '%', "step", '>', '<', ')', ','] + 29 | expr . '/' expr + 30 | expr . '%' expr $default reduce using rule 28 (expr) - Conflict between rule 28 and token '+' resolved as reduce ('+' < '%'). - Conflict between rule 28 and token '-' resolved as reduce ('-' < '%'). + Conflict between rule 28 and token '+' resolved as reduce ('+' < '*'). + Conflict between rule 28 and token '-' resolved as reduce ('-' < '*'). Conflict between rule 28 and token '*' resolved as reduce (%left '*'). Conflict between rule 28 and token '/' resolved as reduce (%left '/'). Conflict between rule 28 and token '%' resolved as reduce (%left '%'). -状態 62 +state 64 - 20 comp_expr: expr '>' expr . ["\n", "then"] - 24 expr: expr . '-' expr - 25 | expr . '+' expr - 26 | expr . '*' expr - 27 | expr . '/' expr - 28 | expr . '%' expr + 26 expr: expr . '-' expr + 27 | expr . '+' expr + 28 | expr . '*' expr + 29 | expr . '/' expr ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', '*', '/', '%', "step", '>', '<', ')', ','] + 29 | expr '/' expr . ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', '*', '/', '%', "step", '>', '<', ')', ','] + 30 | expr . '%' expr - '+' shift, and go to state 41 - '-' shift, and go to state 42 - '*' shift, and go to state 43 - '/' shift, and go to state 44 - '%' shift, and go to state 45 + $default reduce using rule 29 (expr) - $default reduce using rule 20 (comp_expr) + Conflict between rule 29 and token '+' resolved as reduce ('+' < '/'). + Conflict between rule 29 and token '-' resolved as reduce ('-' < '/'). + Conflict between rule 29 and token '*' resolved as reduce (%left '*'). + Conflict between rule 29 and token '/' resolved as reduce (%left '/'). + Conflict between rule 29 and token '%' resolved as reduce (%left '%'). -状態 63 +state 65 + + 26 expr: expr . '-' expr + 27 | expr . '+' expr + 28 | expr . '*' expr + 29 | expr . '/' expr + 30 | expr . '%' expr ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', '*', '/', '%', "step", '>', '<', ')', ','] + 30 | expr '%' expr . ["==", "!=", ">=", "<=", "\n", "then", "to", '+', '-', '*', '/', '%', "step", '>', '<', ')', ','] + + $default reduce using rule 30 (expr) - 22 comp_expr: expr '<' expr . ["\n", "then"] - 24 expr: expr . '-' expr - 25 | expr . '+' expr - 26 | expr . '*' expr - 27 | expr . '/' expr - 28 | expr . '%' expr + Conflict between rule 30 and token '+' resolved as reduce ('+' < '%'). + Conflict between rule 30 and token '-' resolved as reduce ('-' < '%'). + Conflict between rule 30 and token '*' resolved as reduce (%left '*'). + Conflict between rule 30 and token '/' resolved as reduce (%left '/'). + Conflict between rule 30 and token '%' resolved as reduce (%left '%'). + + +state 66 - '+' shift, and go to state 41 - '-' shift, and go to state 42 - '*' shift, and go to state 43 - '/' shift, and go to state 44 - '%' shift, and go to state 45 + 22 comp_expr: expr '>' expr . ["\n", "then"] + 26 expr: expr . '-' expr + 27 | expr . '+' expr + 28 | expr . '*' expr + 29 | expr . '/' expr + 30 | expr . '%' expr + + '+' shift, and go to state 45 + '-' shift, and go to state 46 + '*' shift, and go to state 47 + '/' shift, and go to state 48 + '%' shift, and go to state 49 $default reduce using rule 22 (comp_expr) -状態 64 +state 67 + + 24 comp_expr: expr '<' expr . ["\n", "then"] + 26 expr: expr . '-' expr + 27 | expr . '+' expr + 28 | expr . '*' expr + 29 | expr . '/' expr + 30 | expr . '%' expr + + '+' shift, and go to state 45 + '-' shift, and go to state 46 + '*' shift, and go to state 47 + '/' shift, and go to state 48 + '%' shift, and go to state 49 + + $default reduce using rule 24 (comp_expr) + + +state 68 10 statement: "for" assign "to" expr . "step" expr 11 | "for" assign "to" expr . ["\n"] - 24 expr: expr . '-' expr - 25 | expr . '+' expr - 26 | expr . '*' expr - 27 | expr . '/' expr - 28 | expr . '%' expr + 26 expr: expr . '-' expr + 27 | expr . '+' expr + 28 | expr . '*' expr + 29 | expr . '/' expr + 30 | expr . '%' expr - '+' shift, and go to state 41 - '-' shift, and go to state 42 - '*' shift, and go to state 43 - '/' shift, and go to state 44 - '%' shift, and go to state 45 - "step" shift, and go to state 67 + '+' shift, and go to state 45 + '-' shift, and go to state 46 + '*' shift, and go to state 47 + '/' shift, and go to state 48 + '%' shift, and go to state 49 + "step" shift, and go to state 71 $default reduce using rule 11 (statement) -状態 65 +state 69 - 24 expr: expr . '-' expr - 25 | expr . '+' expr - 26 | expr . '*' expr - 27 | expr . '/' expr - 28 | expr . '%' expr - 36 args: args ',' expr . ["\n", ','] + 26 expr: expr . '-' expr + 27 | expr . '+' expr + 28 | expr . '*' expr + 29 | expr . '/' expr + 30 | expr . '%' expr + 38 args: args ',' expr . ["\n", ','] - '+' shift, and go to state 41 - '-' shift, and go to state 42 - '*' shift, and go to state 43 - '/' shift, and go to state 44 - '%' shift, and go to state 45 + '+' shift, and go to state 45 + '-' shift, and go to state 46 + '*' shift, and go to state 47 + '/' shift, and go to state 48 + '%' shift, and go to state 49 - $default reduce using rule 36 (args) + $default reduce using rule 38 (args) -状態 66 +state 70 - 33 expr: "rand" '(' expr ')' . + 35 expr: "rand" '(' expr ')' . - $default reduce using rule 33 (expr) + $default reduce using rule 35 (expr) -状態 67 +state 71 10 statement: "for" assign "to" expr "step" . expr - 24 expr: . expr '-' expr - 25 | . expr '+' expr - 26 | . expr '*' expr - 27 | . expr '/' expr - 28 | . expr '%' expr - 29 | . '-' expr - 30 | . '(' expr ')' - 31 | . value - 32 | . "ival" - 33 | . "rand" '(' expr ')' - 34 value: . "identifier" + 26 expr: . expr '-' expr + 27 | . expr '+' expr + 28 | . expr '*' expr + 29 | . expr '/' expr + 30 | . expr '%' expr + 31 | . '-' expr + 32 | . '(' expr ')' + 33 | . value + 34 | . "ival" + 35 | . "rand" '(' expr ')' + 36 value: . "identifier" - "ival" shift, and go to state 18 - "identifier" shift, and go to state 2 - "rand" shift, and go to state 19 - '-' shift, and go to state 20 - '(' shift, and go to state 21 + "ival" shift, and go to state 20 + "identifier" shift, and go to state 21 + "rand" shift, and go to state 22 + '-' shift, and go to state 23 + '(' shift, and go to state 24 - expr go to state 68 - value go to state 24 + expr go to state 72 + value go to state 27 -状態 68 +state 72 10 statement: "for" assign "to" expr "step" expr . ["\n"] - 24 expr: expr . '-' expr - 25 | expr . '+' expr - 26 | expr . '*' expr - 27 | expr . '/' expr - 28 | expr . '%' expr + 26 expr: expr . '-' expr + 27 | expr . '+' expr + 28 | expr . '*' expr + 29 | expr . '/' expr + 30 | expr . '%' expr - '+' shift, and go to state 41 - '-' shift, and go to state 42 - '*' shift, and go to state 43 - '/' shift, and go to state 44 - '%' shift, and go to state 45 + '+' shift, and go to state 45 + '-' shift, and go to state 46 + '*' shift, and go to state 47 + '/' shift, and go to state 48 + '%' shift, and go to state 49 $default reduce using rule 10 (statement) diff -r fbe42292d479 -r 3cea2e8a0e4b Bison-Flex/BasicCompiler-StackBase/UTF8/script-parser.yy --- a/Bison-Flex/BasicCompiler-StackBase/UTF8/script-parser.yy Tue May 10 06:43:55 2011 +0900 +++ b/Bison-Flex/BasicCompiler-StackBase/UTF8/script-parser.yy Tue May 10 10:48:02 2011 +0900 @@ -58,6 +58,8 @@ %token TK_END "end" %token TK_RAND "rand" %token TK_PRINT "print" +%token TK_COLON ":" +%token TK_GOTO "goto" %type expr %type comp_expr @@ -98,6 +100,8 @@ | "while" comp_expr { driver.WhileStatement(@1, $2); } | "wend" { driver.WendStatement(@1); } | "print" args { driver.PrintStatement(@1, $2); } + | "identifier" ":" { driver.MakeGotoLabel(@1, $1); } + | "goto" "identifier" { driver.GotoLabel(@1, $2); } | error /* エラーの場合 */ ; @@ -127,6 +131,7 @@ value : "identifier" { $$ = new CValueNode(@1, $1); } ; + args : expr { $$ = new CArgs(@1, $1); } | args ',' expr { $$ = $1->Add(@3, $3); } ; diff -r fbe42292d479 -r 3cea2e8a0e4b Bison-Flex/BasicCompiler-StackBase/UTF8/script-scanner.cc --- a/Bison-Flex/BasicCompiler-StackBase/UTF8/script-scanner.cc Tue May 10 06:43:55 2011 +0900 +++ b/Bison-Flex/BasicCompiler-StackBase/UTF8/script-scanner.cc Tue May 10 10:48:02 2011 +0900 @@ -9,7 +9,7 @@ #define FLEX_SCANNER #define YY_FLEX_MAJOR_VERSION 2 #define YY_FLEX_MINOR_VERSION 5 -#define YY_FLEX_SUBMINOR_VERSION 33 +#define YY_FLEX_SUBMINOR_VERSION 35 #if YY_FLEX_SUBMINOR_VERSION > 0 #define FLEX_BETA #endif @@ -31,7 +31,7 @@ /* C99 systems have . Non-C99 systems may or may not. */ -#if __STDC_VERSION__ >= 199901L +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, * if you want the limit (max/min) macros for int types. @@ -94,11 +94,12 @@ #else /* ! __cplusplus */ -#if __STDC__ +/* C99 requires __STDC__ to be defined as 1. */ +#if defined (__STDC__) #define YY_USE_CONST -#endif /* __STDC__ */ +#endif /* defined (__STDC__) */ #endif /* ! __cplusplus */ #ifdef YY_USE_CONST @@ -152,7 +153,12 @@ typedef struct yy_buffer_state *YY_BUFFER_STATE; #endif -extern int yyleng; +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef size_t yy_size_t; +#endif + +extern yy_size_t yyleng; extern FILE *yyin, *yyout; @@ -178,16 +184,6 @@ #define unput(c) yyunput( c, (yytext_ptr) ) -/* The following is because we cannot portably get our hands on size_t - * (without autoconf's help, which isn't available because we want - * flex-generated scanners to compile on their own). - */ - -#ifndef YY_TYPEDEF_YY_SIZE_T -#define YY_TYPEDEF_YY_SIZE_T -typedef unsigned int yy_size_t; -#endif - #ifndef YY_STRUCT_YY_BUFFER_STATE #define YY_STRUCT_YY_BUFFER_STATE struct yy_buffer_state @@ -205,7 +201,7 @@ /* Number of characters read into yy_ch_buf, not including EOB * characters. */ - int yy_n_chars; + yy_size_t yy_n_chars; /* Whether we "own" the buffer - i.e., we know we created it, * and can realloc() it to grow it, and should free() it to @@ -275,8 +271,8 @@ /* yy_hold_char holds the character lost when yytext is formed. */ static char yy_hold_char; -static int yy_n_chars; /* number of characters read into yy_ch_buf */ -int yyleng; +static yy_size_t yy_n_chars; /* number of characters read into yy_ch_buf */ +yy_size_t yyleng; /* Points to current character in buffer. */ static char *yy_c_buf_p = (char *) 0; @@ -304,7 +300,7 @@ YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ); YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ); -YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,int len ); +YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,yy_size_t len ); void *yyalloc (yy_size_t ); void *yyrealloc (void *,yy_size_t ); @@ -336,7 +332,7 @@ /* Begin user sect3 */ -#define yywrap() 1 +#define yywrap(n) 1 #define YY_SKIP_YYWRAP typedef unsigned char YY_CHAR; @@ -367,8 +363,8 @@ *yy_cp = '\0'; \ (yy_c_buf_p) = yy_cp; -#define YY_NUM_RULES 31 -#define YY_END_OF_BUFFER 32 +#define YY_NUM_RULES 32 +#define YY_END_OF_BUFFER 33 /* This struct is not used in this scanner, but its presence is necessary. */ struct yy_trans_info @@ -376,16 +372,16 @@ flex_int32_t yy_verify; flex_int32_t yy_nxt; }; -static yyconst flex_int16_t yy_accept[75] = +static yyconst flex_int16_t yy_accept[79] = { 0, - 0, 0, 29, 29, 32, 28, 24, 18, 28, 19, - 2, 26, 25, 17, 19, 19, 19, 27, 28, 28, - 27, 27, 27, 27, 27, 27, 27, 27, 29, 30, - 24, 21, 25, 23, 20, 22, 27, 16, 1, 27, - 27, 27, 4, 27, 27, 27, 27, 27, 9, 27, - 27, 29, 27, 13, 8, 27, 27, 27, 3, 27, - 27, 27, 6, 27, 10, 27, 14, 5, 12, 27, - 7, 15, 11, 0 + 0, 0, 30, 30, 33, 29, 25, 19, 29, 20, + 2, 27, 26, 16, 20, 20, 20, 28, 29, 29, + 28, 28, 28, 28, 28, 28, 28, 28, 28, 30, + 31, 25, 22, 26, 24, 21, 23, 28, 18, 1, + 28, 28, 28, 28, 4, 28, 28, 28, 28, 28, + 9, 28, 28, 30, 28, 13, 8, 28, 28, 28, + 28, 3, 28, 28, 28, 6, 28, 17, 10, 28, + 14, 5, 12, 28, 7, 15, 11, 0 } ; static yyconst flex_int32_t yy_ec[256] = @@ -401,8 +397,8 @@ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 1, 15, 1, 16, 14, 1, 17, 14, 14, 18, - 19, 20, 14, 21, 22, 14, 14, 23, 24, 25, - 26, 27, 14, 28, 29, 30, 14, 14, 31, 32, + 19, 20, 21, 22, 23, 14, 14, 24, 25, 26, + 27, 28, 14, 29, 30, 31, 14, 14, 32, 33, 14, 14, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -420,70 +416,74 @@ 1, 1, 1, 1, 1 } ; -static yyconst flex_int32_t yy_meta[33] = +static yyconst flex_int32_t yy_meta[34] = { 0, 1, 1, 2, 1, 1, 1, 1, 3, 3, 1, 1, 1, 1, 3, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3 + 3, 3, 3 } ; -static yyconst flex_int16_t yy_base[78] = +static yyconst flex_int16_t yy_base[82] = { 0, - 0, 0, 83, 82, 84, 87, 81, 87, 70, 87, - 87, 87, 25, 87, 69, 68, 67, 0, 75, 72, - 12, 50, 55, 55, 45, 19, 18, 21, 0, 87, - 70, 87, 37, 87, 87, 87, 0, 87, 87, 42, - 52, 41, 0, 36, 45, 41, 41, 45, 0, 38, - 40, 0, 42, 38, 0, 29, 33, 39, 0, 31, - 37, 31, 0, 33, 0, 21, 0, 0, 0, 24, - 0, 0, 0, 87, 46, 38, 49 + 0, 0, 87, 86, 88, 91, 85, 91, 74, 91, + 91, 91, 26, 91, 73, 72, 71, 0, 79, 76, + 12, 53, 52, 58, 58, 47, 20, 18, 22, 0, + 91, 73, 91, 34, 91, 91, 91, 0, 91, 91, + 44, 55, 43, 40, 0, 37, 46, 42, 42, 47, + 0, 39, 41, 0, 44, 39, 0, 34, 29, 33, + 40, 0, 31, 38, 31, 0, 34, 0, 0, 22, + 0, 0, 0, 33, 0, 0, 0, 91, 45, 47, + 48 } ; -static yyconst flex_int16_t yy_def[78] = +static yyconst flex_int16_t yy_def[82] = { 0, - 74, 1, 75, 75, 74, 74, 74, 74, 74, 74, - 74, 74, 74, 74, 74, 74, 74, 76, 74, 74, - 76, 76, 76, 76, 76, 76, 76, 76, 77, 74, - 74, 74, 74, 74, 74, 74, 76, 74, 74, 76, - 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, - 76, 77, 76, 76, 76, 76, 76, 76, 76, 76, - 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, - 76, 76, 76, 0, 74, 74, 74 + 78, 1, 79, 79, 78, 78, 78, 78, 78, 78, + 78, 78, 78, 78, 78, 78, 78, 80, 78, 78, + 80, 80, 80, 80, 80, 80, 80, 80, 80, 81, + 78, 78, 78, 78, 78, 78, 78, 80, 78, 78, + 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 80, 81, 80, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 80, 0, 78, 78, + 78 } ; -static yyconst flex_int16_t yy_nxt[120] = +static yyconst flex_int16_t yy_nxt[125] = { 0, 6, 7, 8, 9, 6, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 18, 18, 21, 22, - 18, 23, 18, 18, 24, 18, 25, 26, 18, 27, - 28, 18, 33, 33, 40, 46, 41, 47, 48, 50, - 37, 51, 73, 49, 33, 33, 29, 29, 29, 52, - 72, 52, 71, 70, 69, 68, 67, 66, 65, 64, - 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, - 53, 31, 45, 44, 43, 42, 39, 38, 36, 35, - 34, 32, 31, 74, 30, 30, 5, 74, 74, 74, - 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, + 23, 18, 24, 18, 18, 25, 18, 26, 27, 18, + 28, 29, 18, 34, 34, 41, 48, 42, 49, 50, + 52, 34, 34, 53, 51, 30, 30, 30, 54, 38, + 54, 77, 76, 75, 74, 73, 72, 71, 70, 69, + 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, + 58, 57, 56, 55, 32, 47, 46, 45, 44, 43, + 40, 39, 37, 36, 35, 33, 32, 78, 31, 31, + 5, 78, 78, 78, 78, 78, 78, 78, 78, 78, - 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, - 74, 74, 74, 74, 74, 74, 74, 74, 74 + 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, + 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, + 78, 78, 78, 78 } ; -static yyconst flex_int16_t yy_chk[120] = +static yyconst flex_int16_t yy_chk[125] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 13, 13, 21, 26, 21, 26, 27, 28, - 76, 28, 70, 27, 33, 33, 75, 75, 75, 77, - 66, 77, 64, 62, 61, 60, 58, 57, 56, 54, - 53, 51, 50, 48, 47, 46, 45, 44, 42, 41, - 40, 31, 25, 24, 23, 22, 20, 19, 17, 16, - 15, 9, 7, 5, 4, 3, 74, 74, 74, 74, - 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, + 1, 1, 1, 13, 13, 21, 27, 21, 27, 28, + 29, 34, 34, 29, 28, 79, 79, 79, 81, 80, + 81, 74, 70, 67, 65, 64, 63, 61, 60, 59, + 58, 56, 55, 53, 52, 50, 49, 48, 47, 46, + 44, 43, 42, 41, 32, 26, 25, 24, 23, 22, + 20, 19, 17, 16, 15, 9, 7, 5, 4, 3, + 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, - 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, - 74, 74, 74, 74, 74, 74, 74, 74, 74 + 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, + 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, + 78, 78, 78, 78 } ; static yy_state_type yy_last_accepting_state; @@ -544,6 +544,35 @@ static int yy_init_globals (void ); +/* Accessor methods to globals. + These are made visible to non-reentrant scanners for convenience. */ + +int yylex_destroy (void ); + +int yyget_debug (void ); + +void yyset_debug (int debug_flag ); + +YY_EXTRA_TYPE yyget_extra (void ); + +void yyset_extra (YY_EXTRA_TYPE user_defined ); + +FILE *yyget_in (void ); + +void yyset_in (FILE * in_str ); + +FILE *yyget_out (void ); + +void yyset_out (FILE * out_str ); + +yy_size_t yyget_leng (void ); + +char *yyget_text (void ); + +int yyget_lineno (void ); + +void yyset_lineno (int line_number ); + /* Macros after this point can all be overridden by user definitions in * section 1. */ @@ -584,7 +613,7 @@ /* This used to be an fputs(), but since the string might contain NUL's, * we now use fwrite(). */ -#define ECHO (void) fwrite( yytext, yyleng, 1, yyout ) +#define ECHO fwrite( yytext, yyleng, 1, yyout ) #endif /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, @@ -595,7 +624,7 @@ if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ { \ int c = '*'; \ - size_t n; \ + yy_size_t n; \ for ( n = 0; n < max_size && \ (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ buf[n] = (char) c; \ @@ -686,7 +715,7 @@ std::string string_buffer; -#line 690 "script-scanner.cc" +#line 719 "script-scanner.cc" if ( !(yy_init) ) { @@ -739,13 +768,13 @@ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 75 ) + if ( yy_current_state >= 79 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; ++yy_cp; } - while ( yy_current_state != 74 ); + while ( yy_current_state != 78 ); yy_cp = (yy_last_accepting_cpos); yy_current_state = (yy_last_accepting_state); @@ -841,55 +870,60 @@ return token::TK_PRINT; YY_BREAK case 16: -/* rule 16 can match eol */ YY_RULE_SETUP -#line 66 "script-scanner.ll" -yylloc->lines(); +#line 65 "script-scanner.ll" +return token::TK_COLON; YY_BREAK case 17: YY_RULE_SETUP -#line 68 "script-scanner.ll" -return token::TK_NEWLINE; +#line 66 "script-scanner.ll" +return token::TK_GOTO; YY_BREAK case 18: /* rule 18 can match eol */ YY_RULE_SETUP -#line 69 "script-scanner.ll" -{ yylloc->lines(); return token::TK_NEWLINE; } +#line 68 "script-scanner.ll" +yylloc->lines(); YY_BREAK case 19: +/* rule 19 can match eol */ YY_RULE_SETUP -#line 70 "script-scanner.ll" -return yy::script_parser::token_type(yytext[0]); +#line 71 "script-scanner.ll" +{ yylloc->lines(); return token::TK_NEWLINE; } YY_BREAK case 20: YY_RULE_SETUP #line 72 "script-scanner.ll" -return token::TK_EQ; +return yy::script_parser::token_type(yytext[0]); YY_BREAK case 21: YY_RULE_SETUP -#line 73 "script-scanner.ll" -return token::TK_NE; +#line 74 "script-scanner.ll" +return token::TK_EQ; YY_BREAK case 22: YY_RULE_SETUP -#line 74 "script-scanner.ll" -return token::TK_GE; +#line 75 "script-scanner.ll" +return token::TK_NE; YY_BREAK case 23: YY_RULE_SETUP -#line 75 "script-scanner.ll" -return token::TK_LE; +#line 76 "script-scanner.ll" +return token::TK_GE; YY_BREAK case 24: YY_RULE_SETUP #line 77 "script-scanner.ll" -yylloc->step(); +return token::TK_LE; YY_BREAK case 25: YY_RULE_SETUP -#line 78 "script-scanner.ll" +#line 79 "script-scanner.ll" +yylloc->step(); + YY_BREAK +case 26: +YY_RULE_SETUP +#line 80 "script-scanner.ll" { errno = 0; long n = strtol(yytext, NULL, 10); @@ -899,38 +933,38 @@ return token::TK_IVAL; } YY_BREAK -case 26: +case 27: YY_RULE_SETUP -#line 86 "script-scanner.ll" +#line 88 "script-scanner.ll" { yylval->ival = 0; return token::TK_IVAL; } YY_BREAK -case 27: +case 28: YY_RULE_SETUP -#line 90 "script-scanner.ll" +#line 92 "script-scanner.ll" { yylval->sval = new std::string(yytext); return token::TK_IDENTIFIER; } YY_BREAK -case 28: +case 29: YY_RULE_SETUP -#line 94 "script-scanner.ll" +#line 96 "script-scanner.ll" driver.error(*yylloc, "この文字を識別子で使用することはできません。"); YY_BREAK -case 29: +case 30: YY_RULE_SETUP -#line 97 "script-scanner.ll" +#line 99 "script-scanner.ll" YY_BREAK -case 30: -/* rule 30 can match eol */ +case 31: +/* rule 31 can match eol */ YY_RULE_SETUP -#line 98 "script-scanner.ll" +#line 100 "script-scanner.ll" { yylloc->lines(); yylloc->step(); @@ -938,12 +972,12 @@ } YY_BREAK -case 31: +case 32: YY_RULE_SETUP -#line 104 "script-scanner.ll" +#line 106 "script-scanner.ll" ECHO; YY_BREAK -#line 947 "script-scanner.cc" +#line 981 "script-scanner.cc" case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(COMMENT): yyterminate(); @@ -1131,7 +1165,7 @@ else { - int num_to_read = + yy_size_t num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; while ( num_to_read <= 0 ) @@ -1145,7 +1179,7 @@ if ( b->yy_is_our_buffer ) { - int new_size = b->yy_buf_size * 2; + yy_size_t new_size = b->yy_buf_size * 2; if ( new_size <= 0 ) b->yy_buf_size += b->yy_buf_size / 8; @@ -1176,7 +1210,7 @@ /* Read in more data. */ YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - (yy_n_chars), (size_t) num_to_read ); + (yy_n_chars), num_to_read ); YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); } @@ -1200,6 +1234,14 @@ else ret_val = EOB_ACT_CONTINUE_SCAN; + if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + /* Extend the array by 50%, plus the number we really need. */ + yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); + if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); + } + (yy_n_chars) += number_to_move; YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; @@ -1229,7 +1271,7 @@ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 75 ) + if ( yy_current_state >= 79 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; @@ -1257,11 +1299,11 @@ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 75 ) + if ( yy_current_state >= 79 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - yy_is_jam = (yy_current_state == 74); + yy_is_jam = (yy_current_state == 78); return yy_is_jam ? 0 : yy_current_state; } @@ -1290,7 +1332,7 @@ else { /* need more input */ - int offset = (yy_c_buf_p) - (yytext_ptr); + yy_size_t offset = (yy_c_buf_p) - (yytext_ptr); ++(yy_c_buf_p); switch ( yy_get_next_buffer( ) ) @@ -1314,7 +1356,7 @@ case EOB_ACT_END_OF_FILE: { if ( yywrap( ) ) - return EOF; + return 0; if ( ! (yy_did_buffer_switch_on_eof) ) YY_NEW_FILE; @@ -1562,7 +1604,7 @@ */ static void yyensure_buffer_stack (void) { - int num_to_alloc; + yy_size_t num_to_alloc; if (!(yy_buffer_stack)) { @@ -1574,7 +1616,9 @@ (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc (num_to_alloc * sizeof(struct yy_buffer_state*) ); - + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); + memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); (yy_buffer_stack_max) = num_to_alloc; @@ -1592,6 +1636,8 @@ ((yy_buffer_stack), num_to_alloc * sizeof(struct yy_buffer_state*) ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); /* zero only the new slots.*/ memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); @@ -1656,7 +1702,7 @@ /** Get the length of the current token. * */ -int yyget_leng (void) +yy_size_t yyget_leng (void) { return yyleng; } @@ -1804,7 +1850,7 @@ #define YYTABLES_NAME "yytables" -#line 104 "script-scanner.ll" +#line 106 "script-scanner.ll" diff -r fbe42292d479 -r 3cea2e8a0e4b Bison-Flex/BasicCompiler-StackBase/UTF8/script-scanner.ll --- a/Bison-Flex/BasicCompiler-StackBase/UTF8/script-scanner.ll Tue May 10 06:43:55 2011 +0900 +++ b/Bison-Flex/BasicCompiler-StackBase/UTF8/script-scanner.ll Tue May 10 10:48:02 2011 +0900 @@ -62,10 +62,12 @@ "end" return token::TK_END; "rand" return token::TK_RAND; "print" return token::TK_PRINT; + ":" return token::TK_COLON; + "goto" return token::TK_GOTO; \\\n yylloc->lines(); - : return token::TK_NEWLINE; + \n { yylloc->lines(); return token::TK_NEWLINE; } [-+*/%=,()<>] return yy::script_parser::token_type(yytext[0]);