• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14 */
15 
16 /* 尽可能放在parser.cpp靠近头部的地方,与requires相似 */
17 #include <iostream>
18 #include "scanner.h"
19 #include "parser.hpp"
20 #include "script_interpreter.h"
21 #include "log.h"
22 
23 /* 注意:这里的参数由%parse-param决定 */
yylex(uscript::Scanner * scanner,uscript::ScriptInterpreter * interpreter)24 static uscript::Parser::symbol_type yylex(uscript::Scanner* scanner, uscript::ScriptInterpreter* interpreter) {
25     return scanner->nextToken();
26 }
27 
28 using namespace std;
29 using namespace uscript;
30 using namespace updater;
31 
32 // First part of user prologue.
33 
error(const location_type & loc,const std::string & msg)34 void Parser::error(const location_type& loc, const std::string& msg)
35 {
36     LOG(updater::ERROR) << "error " << msg << "  loc " << loc << std::endl;
37 }
38 
39 #include "parser.hpp"
40 
41 #ifndef YY_
42     #if defined YYENABLE_NLS && YYENABLE_NLS
43         #if ENABLE_NLS
44             #include <libintl.h> // FIXME: INFRINGES ON USER NAME SPACE.
45             #define YY_(msgid)dgettext ("bison-runtime", msgid)
46         #endif
47     #endif
48     #ifndef YY_
49         #define YY_(msgid)msgid
50     #endif
51 #endif
52 
53 // Whether we are compiled with exception support.
54 #ifndef YY_EXCEPTIONS
55     #if defined __GNUC__ && !defined __EXCEPTIONS
56         #define YY_EXCEPTIONS 0
57     #else
58         #define YY_EXCEPTIONS 1
59     #endif
60 #endif
61 
62 #define YYRHSLOC(Rhs, K) ((Rhs)[K].location)
63 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
64     If N is 0, then set CURRENT to the empty location which ends
65     the previous symbol: RHS[0] (always defined).  */
66 
67 #ifndef YYLLOC_DEFAULT
68 #define YYLLOC_DEFAULT(Current, Rhs, N)                          \
69     do                                                            \
70     if (N)                                                        \
71     {                                                             \
72         (Current).begin = YYRHSLOC (Rhs, 1).begin;                \
73         (Current).end = YYRHSLOC (Rhs, N).end;                    \
74     }  else {                                                     \
75         (Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end;  \
76     }                                                             \
77     while (false)
78 #endif
79 
80 // Enable debugging if requested.
81 #if YYDEBUG
82 
83 // A pseudo ostream that takes yydebug_ into account.
84 #define YYCDEBUG if (yydebug_)(*yycdebug_)
85 
86 #define YY_SYMBOL_PRINT(Title, Symbol)       \
87     do {                                     \
88         if (yydebug_) {                      \
89             *yycdebug_ << Title << ' ';      \
90             yy_print_ (*yycdebug_, Symbol);  \
91             *yycdebug_ << '\n';              \
92         }                                    \
93     } while (false)
94 
95 #define YY_REDUCE_PRINT(Rule)             \
96     do {                                  \
97         if (yydebug_)                     \
98             yy_reduce_print_ (Rule);      \
99     } while (false)
100 
101 #define YY_STACK_PRINT()             \
102     do {                             \
103         if (yydebug_)                \
104             yy_stack_print_ ();      \
105     } while (false)
106 
107 #else // !YYDEBUG
108 
109 #define YYCDEBUG if (false) std::cerr
110 #define YY_SYMBOL_PRINT(Title, Symbol) YYUSE(Symbol)
111 #define YY_REDUCE_PRINT(Rule)          static_cast<void> (0)
112 #define YY_STACK_PRINT()               static_cast<void> (0)
113 
114 #endif // !YYDEBUG
115 
116 #define yyerrok         (yyerrstatus_ = 0)
117 #define yyclearin       (yyla.clear ())
118 
119 #define YYACCEPT        goto yyacceptlab
120 #define YYABORT         goto yyabortlab
121 #define YYERROR         goto yyerrorlab
122 #define YYRECOVERING() (!!yyerrstatus_)
123 
124 namespace uscript {
125 
126 // Build a parser object.
Parser(uscript::Scanner * scanner_yyarg,uscript::ScriptInterpreter * interpreter_yyarg)127 Parser::Parser(uscript::Scanner* scanner_yyarg, uscript::ScriptInterpreter* interpreter_yyarg)
128 #if YYDEBUG
129     : yydebug_(false),
130     yycdebug_(&std::cerr),
131 #else
132     :
133 #endif
134     scanner(scanner_yyarg),
135     interpreter(interpreter_yyarg) {}
~Parser()136     Parser::~Parser() {}
137 
~syntax_error()138     Parser::syntax_error::~syntax_error() YY_NOEXCEPT YY_NOTHROW {}
139 
140     /*---------------.
141     | symbol kinds.  |
142     `---------------*/
143 
144     // by_state.
by_state()145     Parser::by_state::by_state() YY_NOEXCEPT
146         : state(empty_state) {}
147 
by_state(const by_state & that)148     Parser::by_state::by_state(const by_state& that) YY_NOEXCEPT
149         : state(that.state) {}
150 
clear()151     void Parser::by_state::clear() YY_NOEXCEPT
152     {
153         state = empty_state;
154     }
155 
move(by_state & that)156     void Parser::by_state::move(by_state& that)
157     {
158         state = that.state;
159         that.clear();
160     }
161 
by_state(state_type s)162     Parser::by_state::by_state(state_type s) YY_NOEXCEPT
163         : state(s) {}
164 
165     Parser::symbol_kind_type
kind() const166     Parser::by_state::kind() const YY_NOEXCEPT
167     {
168         if (state == empty_state) {
169             return symbol_kind::S_YYEMPTY;
170         } else {
171             return YY_CAST (symbol_kind_type, yystos_[+state]);
172         }
173     }
174 
stack_symbol_type()175     Parser::stack_symbol_type::stack_symbol_type() {}
176 
stack_symbol_type(YY_RVREF (stack_symbol_type)that)177     Parser::stack_symbol_type::stack_symbol_type(YY_RVREF (stack_symbol_type)that)
178         : super_type(YY_MOVE(that.state), YY_MOVE(that.location))
179     {
180         switch (that.kind()) {
181             case symbol_kind::S_function_definition: // function_definition
182                 value.YY_MOVE_OR_COPY< ScriptFunction* > (YY_MOVE (that.value));
183                 break;
184 
185             case symbol_kind::S_arglist: // arglist
186                 value.YY_MOVE_OR_COPY< ScriptParams* >(YY_MOVE(that.value));
187                 break;
188 
189             case symbol_kind::S_definition_or_statement: // definition_or_statement
190                 /* fallthrough */
191             case symbol_kind::S_expression: // expression
192                 /* fallthrough */
193             case symbol_kind::S_value_expression: // value_expression
194                 /* fallthrough */
195             case symbol_kind::S_compare_expression: // compare_expression
196                 /* fallthrough */
197             case symbol_kind::S_add_sub_expression: // add_sub_expression
198                 /* fallthrough */
199             case symbol_kind::S_mul_div_expression: // mul_div_expression
200                 /* fallthrough */
201             case symbol_kind::S_primary_expression: // primary_expression
202                 /* fallthrough */
203             case symbol_kind::S_arg: // arg
204                 /* fallthrough */
205             case symbol_kind::S_expression_option: // expression_option
206                 value.YY_MOVE_OR_COPY< UScriptExpression* > (YY_MOVE (that.value));
207                 break;
208 
209             case symbol_kind::S_statement: // statement
210                 /* fallthrough */
211             case symbol_kind::S_expression_statement: // expression_statement
212                 /* fallthrough */
213             case symbol_kind::S_for_statement: // for_statement
214                 /* fallthrough */
215             case symbol_kind::S_while_statement: // while_statement
216                 /* fallthrough */
217             case symbol_kind::S_if_statement: // if_statement
218                 /* fallthrough */
219             case symbol_kind::S_break_statement: // break_statement
220                 /* fallthrough */
221             case symbol_kind::S_continue_statement: // continue_statement
222                 /* fallthrough */
223             case symbol_kind::S_return_statement: // return_statement
224                 value.YY_MOVE_OR_COPY< UScriptStatement* > (YY_MOVE (that.value));
225                 break;
226 
227             case symbol_kind::S_statement_list: // statement_list
228                 /* fallthrough */
229             case symbol_kind::S_block: // block
230                 value.YY_MOVE_OR_COPY< UScriptStatementList* > (YY_MOVE (that.value));
231                 break;
232 
233             case symbol_kind::S_FLOAT: // FLOAT
234                 value.YY_MOVE_OR_COPY< float > (YY_MOVE (that.value));
235                 break;
236 
237             case symbol_kind::S_NUMBER: // NUMBER
238                 value.YY_MOVE_OR_COPY< int > (YY_MOVE (that.value));
239                 break;
240 
241             case symbol_kind::S_VAR: // VAR
242                 /* fallthrough */
243             case symbol_kind::S_FUNCTION: // FUNCTION
244                 /* fallthrough */
245             case symbol_kind::S_GLOBAL: // GLOBAL
246                 /* fallthrough */
247             case symbol_kind::S_FOR: // FOR
248                 /* fallthrough */
249             case symbol_kind::S_WHILE: // WHILE
250                 /* fallthrough */
251             case symbol_kind::S_IF: // IF
252                 /* fallthrough */
253             case symbol_kind::S_ELSE: // ELSE
254                 /* fallthrough */
255             case symbol_kind::S_ADD: // ADD
256                 /* fallthrough */
257             case symbol_kind::S_SUB: // SUB
258                 /* fallthrough */
259             case symbol_kind::S_MUL: // MUL
260                 /* fallthrough */
261             case symbol_kind::S_DIV: // DIV
262                 /* fallthrough */
263             case symbol_kind::S_ASSIGN: // ASSIGN
264                 /* fallthrough */
265             case symbol_kind::S_AND: // AND
266                 /* fallthrough */
267             case symbol_kind::S_OR: // OR
268                 /* fallthrough */
269             case symbol_kind::S_EQ: // EQ
270                 /* fallthrough */
271             case symbol_kind::S_NE: // NE
272                 /* fallthrough */
273             case symbol_kind::S_GT: // GT
274                 /* fallthrough */
275             case symbol_kind::S_GE: // GE
276                 /* fallthrough */
277             case symbol_kind::S_LT: // LT
278                 /* fallthrough */
279             case symbol_kind::S_LE: // LE
280                 /* fallthrough */
281             case symbol_kind::S_LP: // LP
282                 /* fallthrough */
283             case symbol_kind::S_RP: // RP
284                 /* fallthrough */
285             case symbol_kind::S_LC: // LC
286                 /* fallthrough */
287             case symbol_kind::S_RC: // RC
288                 /* fallthrough */
289             case symbol_kind::S_SEMICOLON: // SEMICOLON
290                 /* fallthrough */
291             case symbol_kind::S_IDENTIFIER: // IDENTIFIER
292                 /* fallthrough */
293             case symbol_kind::S_BREAK: // BREAK
294                 /* fallthrough */
295             case symbol_kind::S_CONTINUE: // CONTINUE
296                 /* fallthrough */
297             case symbol_kind::S_RETURN: // RETURN
298                 /* fallthrough */
299             case symbol_kind::S_COMMA: // COMMA
300                 /* fallthrough */
301             case symbol_kind::S_STRING: // STRING
302                 value.YY_MOVE_OR_COPY< string > (YY_MOVE (that.value));
303                 break;
304 
305             default:
306                 break;
307         }
308 #if 201103L <= YY_CPLUSPLUS
309         // that is emptied.
310         that.state = empty_state;
311 #endif
312     }
313 
stack_symbol_type(state_type s,YY_MOVE_REF (symbol_type)that)314     Parser::stack_symbol_type::stack_symbol_type(state_type s, YY_MOVE_REF (symbol_type)that)
315         : super_type(s, YY_MOVE(that.location))
316     {
317         switch(that.kind()) {
318             case symbol_kind::S_function_definition: // function_definition
319                 value.move< ScriptFunction* > (YY_MOVE (that.value));
320                 break;
321 
322             case symbol_kind::S_arglist: // arglist
323                 value.move< ScriptParams* > (YY_MOVE (that.value));
324                 break;
325 
326             case symbol_kind::S_definition_or_statement: // definition_or_statement
327                 /* fallthrough */
328             case symbol_kind::S_expression: // expression
329                 /* fallthrough */
330             case symbol_kind::S_value_expression: // value_expression
331                 /* fallthrough */
332             case symbol_kind::S_compare_expression: // compare_expression
333                 /* fallthrough */
334             case symbol_kind::S_add_sub_expression: // add_sub_expression
335                 /* fallthrough */
336             case symbol_kind::S_mul_div_expression: // mul_div_expression
337                 /* fallthrough */
338             case symbol_kind::S_primary_expression: // primary_expression
339                 /* fallthrough */
340             case symbol_kind::S_arg: // arg
341                 /* fallthrough */
342             case symbol_kind::S_expression_option: // expression_option
343                 value.move< UScriptExpression* > (YY_MOVE (that.value));
344                 break;
345 
346             case symbol_kind::S_statement: // statement
347                 /* fallthrough */
348             case symbol_kind::S_expression_statement: // expression_statement
349                 /* fallthrough */
350             case symbol_kind::S_for_statement: // for_statement
351                 /* fallthrough */
352             case symbol_kind::S_while_statement: // while_statement
353                 /* fallthrough */
354             case symbol_kind::S_if_statement: // if_statement
355                 /* fallthrough */
356             case symbol_kind::S_break_statement: // break_statement
357                 /* fallthrough */
358             case symbol_kind::S_continue_statement: // continue_statement
359                 /* fallthrough */
360             case symbol_kind::S_return_statement: // return_statement
361                 value.move< UScriptStatement* > (YY_MOVE (that.value));
362                 break;
363 
364             case symbol_kind::S_statement_list: // statement_list
365                 /* fallthrough */
366             case symbol_kind::S_block: // block
367                 value.move< UScriptStatementList* > (YY_MOVE (that.value));
368                 break;
369 
370             case symbol_kind::S_FLOAT: // FLOAT
371                 value.move< float > (YY_MOVE (that.value));
372                 break;
373 
374             case symbol_kind::S_NUMBER: // NUMBER
375                 value.move< int > (YY_MOVE (that.value));
376                 break;
377 
378             case symbol_kind::S_VAR: // VAR
379                 /* fallthrough */
380             case symbol_kind::S_FUNCTION: // FUNCTION
381                 /* fallthrough */
382             case symbol_kind::S_GLOBAL: // GLOBAL
383                 /* fallthrough */
384             case symbol_kind::S_FOR: // FOR
385                 /* fallthrough */
386             case symbol_kind::S_WHILE: // WHILE
387                 /* fallthrough */
388             case symbol_kind::S_IF: // IF
389                 /* fallthrough */
390             case symbol_kind::S_ELSE: // ELSE
391                 /* fallthrough */
392             case symbol_kind::S_ADD: // ADD
393                 /* fallthrough */
394             case symbol_kind::S_SUB: // SUB
395                 /* fallthrough */
396             case symbol_kind::S_MUL: // MUL
397                 /* fallthrough */
398             case symbol_kind::S_DIV: // DIV
399                 /* fallthrough */
400             case symbol_kind::S_ASSIGN: // ASSIGN
401                 /* fallthrough */
402             case symbol_kind::S_AND: // AND
403                 /* fallthrough */
404             case symbol_kind::S_OR: // OR
405                 /* fallthrough */
406             case symbol_kind::S_EQ: // EQ
407                 /* fallthrough */
408             case symbol_kind::S_NE: // NE
409                 /* fallthrough */
410             case symbol_kind::S_GT: // GT
411                 /* fallthrough */
412             case symbol_kind::S_GE: // GE
413                 /* fallthrough */
414             case symbol_kind::S_LT: // LT
415                 /* fallthrough */
416             case symbol_kind::S_LE: // LE
417                 /* fallthrough */
418             case symbol_kind::S_LP: // LP
419                 /* fallthrough */
420             case symbol_kind::S_RP: // RP
421                 /* fallthrough */
422             case symbol_kind::S_LC: // LC
423                 /* fallthrough */
424             case symbol_kind::S_RC: // RC
425                 /* fallthrough */
426             case symbol_kind::S_SEMICOLON: // SEMICOLON
427                 /* fallthrough */
428             case symbol_kind::S_IDENTIFIER: // IDENTIFIER
429                 /* fallthrough */
430             case symbol_kind::S_BREAK: // BREAK
431                 /* fallthrough */
432             case symbol_kind::S_CONTINUE: // CONTINUE
433                 /* fallthrough */
434             case symbol_kind::S_RETURN: // RETURN
435                 /* fallthrough */
436             case symbol_kind::S_COMMA: // COMMA
437                 /* fallthrough */
438             case symbol_kind::S_STRING: // STRING
439                 value.move< string > (YY_MOVE (that.value));
440                 break;
441 
442             default:
443                 break;
444         }
445         // that is emptied.
446         that.kind_ = symbol_kind::S_YYEMPTY;
447     }
448 
449 #if YY_CPLUSPLUS < 201103L
450     Parser::stack_symbol_type&
operator =(const stack_symbol_type & that)451     Parser::stack_symbol_type::operator=(const stack_symbol_type &that)
452     {
453         state = that.state;
454         switch (that.kind()) {
455             case symbol_kind::S_function_definition: // function_definition
456                 value.copy< ScriptFunction* > (that.value);
457                 break;
458 
459             case symbol_kind::S_arglist: // arglist
460                 value.copy< ScriptParams* > (that.value);
461                 break;
462 
463             case symbol_kind::S_definition_or_statement: // definition_or_statement
464                 /* fallthrough */
465             case symbol_kind::S_expression: // expression
466                 /* fallthrough */
467             case symbol_kind::S_value_expression: // value_expression
468                 /* fallthrough */
469             case symbol_kind::S_compare_expression: // compare_expression
470                 /* fallthrough */
471             case symbol_kind::S_add_sub_expression: // add_sub_expression
472                 /* fallthrough */
473             case symbol_kind::S_mul_div_expression: // mul_div_expression
474                 /* fallthrough */
475             case symbol_kind::S_primary_expression: // primary_expression
476                 /* fallthrough */
477             case symbol_kind::S_arg: // arg
478                 /* fallthrough */
479             case symbol_kind::S_expression_option: // expression_option
480                 value.copy< UScriptExpression* > (that.value);
481                 break;
482 
483             case symbol_kind::S_statement: // statement
484                 /* fallthrough */
485             case symbol_kind::S_expression_statement: // expression_statement
486                 /* fallthrough */
487             case symbol_kind::S_for_statement: // for_statement
488                 /* fallthrough */
489             case symbol_kind::S_while_statement: // while_statement
490                 /* fallthrough */
491             case symbol_kind::S_if_statement: // if_statement
492                 /* fallthrough */
493             case symbol_kind::S_break_statement: // break_statement
494                 /* fallthrough */
495             case symbol_kind::S_continue_statement: // continue_statement
496                 /* fallthrough */
497             case symbol_kind::S_return_statement: // return_statement
498                 value.copy< UScriptStatement* > (that.value);
499                 break;
500 
501             case symbol_kind::S_statement_list: // statement_list
502                 /* fallthrough */
503             case symbol_kind::S_block: // block
504                 value.copy< UScriptStatementList* > (that.value);
505                 break;
506 
507             case symbol_kind::S_FLOAT: // FLOAT
508                 value.copy< float > (that.value);
509                 break;
510 
511             case symbol_kind::S_NUMBER: // NUMBER
512                 value.copy< int > (that.value);
513                 break;
514 
515             case symbol_kind::S_VAR: // VAR
516                 /* fallthrough */
517             case symbol_kind::S_FUNCTION: // FUNCTION
518                 /* fallthrough */
519             case symbol_kind::S_GLOBAL: // GLOBAL
520                 /* fallthrough */
521             case symbol_kind::S_FOR: // FOR
522                 /* fallthrough */
523             case symbol_kind::S_WHILE: // WHILE
524                 /* fallthrough */
525             case symbol_kind::S_IF: // IF
526                 /* fallthrough */
527             case symbol_kind::S_ELSE: // ELSE
528                 /* fallthrough */
529             case symbol_kind::S_ADD: // ADD
530                 /* fallthrough */
531             case symbol_kind::S_SUB: // SUB
532                 /* fallthrough */
533             case symbol_kind::S_MUL: // MUL
534                 /* fallthrough */
535             case symbol_kind::S_DIV: // DIV
536                 /* fallthrough */
537             case symbol_kind::S_ASSIGN: // ASSIGN
538                 /* fallthrough */
539             case symbol_kind::S_AND: // AND
540                 /* fallthrough */
541             case symbol_kind::S_OR: // OR
542                 /* fallthrough */
543             case symbol_kind::S_EQ: // EQ
544                 /* fallthrough */
545             case symbol_kind::S_NE: // NE
546                 /* fallthrough */
547             case symbol_kind::S_GT: // GT
548                 /* fallthrough */
549             case symbol_kind::S_GE: // GE
550                 /* fallthrough */
551             case symbol_kind::S_LT: // LT
552                 /* fallthrough */
553             case symbol_kind::S_LE: // LE
554                 /* fallthrough */
555             case symbol_kind::S_LP: // LP
556                 /* fallthrough */
557             case symbol_kind::S_RP: // RP
558                 /* fallthrough */
559             case symbol_kind::S_LC: // LC
560                 /* fallthrough */
561             case symbol_kind::S_RC: // RC
562                 /* fallthrough */
563             case symbol_kind::S_SEMICOLON: // SEMICOLON
564                 /* fallthrough */
565             case symbol_kind::S_IDENTIFIER: // IDENTIFIER
566                 /* fallthrough */
567             case symbol_kind::S_BREAK: // BREAK
568                 /* fallthrough */
569             case symbol_kind::S_CONTINUE: // CONTINUE
570                 /* fallthrough */
571             case symbol_kind::S_RETURN: // RETURN
572                 /* fallthrough */
573             case symbol_kind::S_COMMA: // COMMA
574                 /* fallthrough */
575             case symbol_kind::S_STRING: // STRING
576                 value.copy< string > (that.value);
577                 break;
578 
579             default:
580                 break;
581         }
582         location = that.location;
583         return *this;
584     }
585 
operator =(stack_symbol_type & that)586     Parser::stack_symbol_type& Parser::stack_symbol_type::operator=(stack_symbol_type &that)
587     {
588         state = that.state;
589         switch (that.kind()) {
590             case symbol_kind::S_function_definition: // function_definition
591                 value.move<ScriptFunction*>(that.value);
592                 break;
593 
594             case symbol_kind::S_arglist: // arglist
595                 value.move<ScriptParams*>(that.value);
596                 break;
597 
598             case symbol_kind::S_definition_or_statement: // definition_or_statement
599                 /* fallthrough */
600             case symbol_kind::S_expression: // expression
601                 /* fallthrough */
602             case symbol_kind::S_value_expression: // value_expression
603                 /* fallthrough */
604             case symbol_kind::S_compare_expression: // compare_expression
605                 /* fallthrough */
606             case symbol_kind::S_add_sub_expression: // add_sub_expression
607                 /* fallthrough */
608             case symbol_kind::S_mul_div_expression: // mul_div_expression
609                 /* fallthrough */
610             case symbol_kind::S_primary_expression: // primary_expression
611                 /* fallthrough */
612             case symbol_kind::S_arg: // arg
613                 /* fallthrough */
614             case symbol_kind::S_expression_option: // expression_option
615                 value.move<UScriptExpression*>(that.value);
616                 break;
617 
618             case symbol_kind::S_statement: // statement
619                 /* fallthrough */
620             case symbol_kind::S_expression_statement: // expression_statement
621                 /* fallthrough */
622             case symbol_kind::S_for_statement: // for_statement
623                 /* fallthrough */
624             case symbol_kind::S_while_statement: // while_statement
625                 /* fallthrough */
626             case symbol_kind::S_if_statement: // if_statement
627                 /* fallthrough */
628             case symbol_kind::S_break_statement: // break_statement
629                 /* fallthrough */
630             case symbol_kind::S_continue_statement: // continue_statement
631                 /* fallthrough */
632             case symbol_kind::S_return_statement: // return_statement
633                 value.move<UScriptStatement*>(that.value);
634                 break;
635 
636             case symbol_kind::S_statement_list: // statement_list
637                 /* fallthrough */
638             case symbol_kind::S_block: // block
639                 value.move<UScriptStatementList*> (that.value);
640                 break;
641 
642             case symbol_kind::S_FLOAT: // FLOAT
643                 value.move<float> (that.value);
644                 break;
645 
646             case symbol_kind::S_NUMBER: // NUMBER
647                 value.move<int> (that.value);
648                 break;
649 
650             case symbol_kind::S_VAR: // VAR
651                 /* fallthrough */
652             case symbol_kind::S_FUNCTION: // FUNCTION
653                 /* fallthrough */
654             case symbol_kind::S_GLOBAL: // GLOBAL
655                 /* fallthrough */
656             case symbol_kind::S_FOR: // FOR
657                 /* fallthrough */
658             case symbol_kind::S_WHILE: // WHILE
659                 /* fallthrough */
660             case symbol_kind::S_IF: // IF
661                 /* fallthrough */
662             case symbol_kind::S_ELSE: // ELSE
663                 /* fallthrough */
664             case symbol_kind::S_ADD: // ADD
665                 /* fallthrough */
666             case symbol_kind::S_SUB: // SUB
667                 /* fallthrough */
668             case symbol_kind::S_MUL: // MUL
669                 /* fallthrough */
670             case symbol_kind::S_DIV: // DIV
671                 /* fallthrough */
672             case symbol_kind::S_ASSIGN: // ASSIGN
673                 /* fallthrough */
674             case symbol_kind::S_AND: // AND
675                 /* fallthrough */
676             case symbol_kind::S_OR: // OR
677                 /* fallthrough */
678             case symbol_kind::S_EQ: // EQ
679                 /* fallthrough */
680             case symbol_kind::S_NE: // NE
681                 /* fallthrough */
682             case symbol_kind::S_GT: // GT
683                 /* fallthrough */
684             case symbol_kind::S_GE: // GE
685                 /* fallthrough */
686             case symbol_kind::S_LT: // LT
687                 /* fallthrough */
688             case symbol_kind::S_LE: // LE
689                 /* fallthrough */
690             case symbol_kind::S_LP: // LP
691                 /* fallthrough */
692             case symbol_kind::S_RP: // RP
693                 /* fallthrough */
694             case symbol_kind::S_LC: // LC
695                 /* fallthrough */
696             case symbol_kind::S_RC: // RC
697                 /* fallthrough */
698             case symbol_kind::S_SEMICOLON: // SEMICOLON
699                 /* fallthrough */
700             case symbol_kind::S_IDENTIFIER: // IDENTIFIER
701                 /* fallthrough */
702             case symbol_kind::S_BREAK: // BREAK
703                 /* fallthrough */
704             case symbol_kind::S_CONTINUE: // CONTINUE
705                 /* fallthrough */
706             case symbol_kind::S_RETURN: // RETURN
707                 /* fallthrough */
708             case symbol_kind::S_COMMA: // COMMA
709                 /* fallthrough */
710             case symbol_kind::S_STRING: // STRING
711                 value.move<string>(that.value);
712                 break;
713 
714             default:
715                 break;
716         }
717         location = that.location;
718         // that is emptied.
719         that.state = empty_state;
720         return *this;
721     }
722 #endif
723 
724     template <typename Base>
yy_destroy_(const char * yymsg,basic_symbol<Base> & yysym) const725     void Parser::yy_destroy_(const char *yymsg, basic_symbol<Base> &yysym) const
726     {
727         if (yymsg) {
728             YY_SYMBOL_PRINT (yymsg, yysym);
729         }
730     }
731 
732 #if YYDEBUG
733     template <typename Base>
yy_print_(std::ostream & yyo,const basic_symbol<Base> & yysym) const734     void Parser::yy_print_(std::ostream& yyo, const basic_symbol<Base>& yysym) const
735     {
736         std::ostream &yyoutput = yyo;
737         YYUSE(yyoutput);
738         if (yysym.empty ()) {
739             yyo << "empty symbol";
740         } else {
741             symbol_kind_type yykind = yysym.kind ();
742             yyo << (yykind < YYNTOKENS ? "token" : "nterm") <<
743                 ' ' << yysym.name () << " (" << yysym.location << ": ";
744             YYUSE (yykind);
745             yyo << ')';
746         }
747     }
748 #endif
749 
yypush_(const char * m,YY_MOVE_REF (stack_symbol_type)sym)750     void Parser::yypush_(const char *m, YY_MOVE_REF (stack_symbol_type)sym)
751     {
752         if (m) {
753             YY_SYMBOL_PRINT (m, sym);
754         }
755         yystack_.push (YY_MOVE (sym));
756     }
757 
yypush_(const char * m,state_type s,YY_MOVE_REF (symbol_type)sym)758     void Parser::yypush_(const char *m, state_type s, YY_MOVE_REF (symbol_type)sym)
759     {
760 #if 201103L <= YY_CPLUSPLUS
761         yypush_(m, stack_symbol_type(s, std::move (sym)));
762 #else
763         stack_symbol_type ss(s, sym);
764         yypush_(m, ss);
765 #endif
766     }
767 
yypop_(int n)768     void Parser::yypop_(int n)
769     {
770         yystack_.pop(n);
771     }
772 
773 #if YYDEBUG
debug_stream() const774     std::ostream& Parser::debug_stream() const
775     {
776         return *yycdebug_;
777     }
778 
set_debug_stream(std::ostream & o)779     void Parser::set_debug_stream(std::ostream &o)
780     {
781         yycdebug_ = &o;
782     }
783 
debug_level() const784     Parser::debug_level_type Parser::debug_level() const
785     {
786         return yydebug_;
787     }
788 
set_debug_level(debug_level_type l)789     void Parser::set_debug_level(debug_level_type l)
790     {
791         yydebug_ = l;
792     }
793 #endif // YYDEBUG
794 
yy_lr_goto_state_(state_type yystate,int yysym)795     Parser::state_type Parser::yy_lr_goto_state_(state_type yystate, int yysym)
796     {
797         int yyr = yypgoto_[yysym - YYNTOKENS] + yystate;
798         if (0 <= yyr && yyr <= yylast_ && yycheck_[yyr] == yystate) {
799             return yytable_[yyr];
800         } else {
801             return yydefgoto_[yysym - YYNTOKENS];
802         }
803     }
804 
yy_pact_value_is_default_(int yyvalue)805     bool Parser::yy_pact_value_is_default_(int yyvalue)
806     {
807         return yyvalue == yypact_ninf_;
808     }
809 
yy_table_value_is_error_(int yyvalue)810     bool Parser::yy_table_value_is_error_(int yyvalue)
811     {
812         return yyvalue == yytable_ninf_;
813     }
814 
operator ()()815     int Parser::operator()()
816     {
817         return parse();
818     }
819 
parse()820     int Parser::parse()
821     {
822         int yyn;
823         // Length of the RHS of the rule being reduced.
824         int yylen = 0;
825 
826         // Error handling.
827         int yynerrs_ = 0;
828         int yyerrstatus_ = 0;
829 
830         // The lookahead symbol.
831         symbol_type yyla;
832 
833         // The locations where the error started and ended.
834         stack_symbol_type yyerror_range[3];
835 
836         // The return value of parse ().
837         int yyresult;
838 
839 #if YY_EXCEPTIONS
840         try
841 #endif // YY_EXCEPTIONS
842         {
843             YYCDEBUG << "Starting parse\n";
844             /* Initialize the stack.  The initial state will be set in
845             * yynewstate, since the latter expects the semantical and the
846             * location values to have been already stored, initialize these
847             * stacks with a primary value.
848             */
849             yystack_.clear ();
850             yypush_(YY_NULLPTR, 0, YY_MOVE (yyla));
851 
852             /*-----------------------------------------------.
853             | yynewstate -- push a new symbol on the stack.  |
854             `-----------------------------------------------*/
855             yynewstate:
856             YYCDEBUG << " Entering state" << int (yystack_[0].state) << '\n';
857             YY_STACK_PRINT();
858 
859             // Accept?
860             if (yystack_[0].state == yyfinal_) {
861                 YYACCEPT;
862             }
863 
864             goto yybackup;
865 
866 
867             /*-----------.
868             | yybackup.  |
869             `-----------*/
870 yybackup:
871             // Try to take a decision without lookahead.
872             yyn = yypact_[+yystack_[0].state];
873             if (yy_pact_value_is_default_(yyn)) {
874                 goto yydefault;
875             }
876 
877             // Read a lookahead token.
878             if (yyla.empty()) {
879                 YYCDEBUG << "Reading a token\n";
880 #if YY_EXCEPTIONS
881                 try
882 #endif // YY_EXCEPTIONS
883                 {
884                     symbol_type yylookahead(yylex (scanner, interpreter));
885                     yyla.move(yylookahead);
886                 }
887 #if YY_EXCEPTIONS
888                 catch (const syntax_error& yyexc) {
889                     YYCDEBUG << "Caught exception: " << yyexc.what() << '\n';
890                     error(yyexc);
891                     goto yyerrlab1;
892                 }
893 #endif // YY_EXCEPTIONS
894             }
895             YY_SYMBOL_PRINT("Next token is", yyla);
896             if (yyla.kind() == symbol_kind::S_YYerror) {
897                 // The scanner already issued an error message, process directly
898                 // to error recovery.  But do not keep the error token as
899                 // lookahead, it is too special and may lead us to an endless
900                 // loop in error recovery. */
901                 yyla.kind_ = symbol_kind::S_YYUNDEF;
902                 goto yyerrlab1;
903             }
904 
905             /* If the proper action on seeing token YYLA.TYPE is to reduce or
906               to detect an error, take that action.  */
907             yyn += yyla.kind();
908             if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yyla.kind())
909             {
910                 goto yydefault;
911             }
912 
913             // Reduce or error.
914             yyn = yytable_[yyn];
915             if (yyn <= 0) {
916                 if (yy_table_value_is_error_(yyn)) {
917                     goto yyerrlab;
918                 }
919                 yyn = -yyn;
920                 goto yyreduce;
921             }
922 
923             // Count tokens shifted since error; after three, turn off error status.
924             if (yyerrstatus_) {
925                 --yyerrstatus_;
926             }
927 
928             // Shift the lookahead token.
929             yypush_ ("Shifting", state_type(yyn), YY_MOVE(yyla));
930             goto yynewstate;
931 
932             /*-----------------------------------------------------------.
933             | yydefault -- do the default action for the current state.  |
934             `-----------------------------------------------------------*/
935 yydefault:
936             yyn = yydefact_[+yystack_[0].state];
937             if (yyn == 0) {
938                 goto yyerrlab;
939             }
940             goto yyreduce;
941 
942 
943             /*-----------------------------.
944             | yyreduce -- do a reduction.  |
945             `-----------------------------*/
946 yyreduce:
947             yylen = yyr2_[yyn];
948             {
949                 stack_symbol_type yylhs;
950                 yylhs.state = yy_lr_goto_state_ (yystack_[yylen].state, yyr1_[yyn]);
951                 /* Variants are always initialized to an empty instance of the
952                   correct type. The default '$$ = $1' action is NOT applied
953                   when using variants.  */
954                 switch (yyr1_[yyn]) {
955                     case symbol_kind::S_function_definition: // function_definition
956                         yylhs.value.emplace< ScriptFunction* >();
957                         break;
958 
959                     case symbol_kind::S_arglist: // arglist
960                         yylhs.value.emplace< ScriptParams* >();
961                         break;
962 
963                     case symbol_kind::S_definition_or_statement: // definition_or_statement
964                         /* fallthrough */
965                     case symbol_kind::S_expression: // expression
966                         /* fallthrough */
967                     case symbol_kind::S_value_expression: // value_expression
968                         /* fallthrough */
969                     case symbol_kind::S_compare_expression: // compare_expression
970                         /* fallthrough */
971                     case symbol_kind::S_add_sub_expression: // add_sub_expression
972                         /* fallthrough */
973                     case symbol_kind::S_mul_div_expression: // mul_div_expression
974                         /* fallthrough */
975                     case symbol_kind::S_primary_expression: // primary_expression
976                         /* fallthrough */
977                     case symbol_kind::S_arg: // arg
978                         /* fallthrough */
979                     case symbol_kind::S_expression_option: // expression_option
980                         yylhs.value.emplace< UScriptExpression* >();
981                         break;
982 
983                     case symbol_kind::S_statement: // statement
984                         /* fallthrough */
985                     case symbol_kind::S_expression_statement: // expression_statement
986                         /* fallthrough */
987                     case symbol_kind::S_for_statement: // for_statement
988                         /* fallthrough */
989                     case symbol_kind::S_while_statement: // while_statement
990                         /* fallthrough */
991                     case symbol_kind::S_if_statement: // if_statement
992                         /* fallthrough */
993                     case symbol_kind::S_break_statement: // break_statement
994                         /* fallthrough */
995                     case symbol_kind::S_continue_statement: // continue_statement
996                         /* fallthrough */
997                     case symbol_kind::S_return_statement: // return_statement
998                         yylhs.value.emplace< UScriptStatement* >();
999                         break;
1000 
1001                     case symbol_kind::S_statement_list: // statement_list
1002                         /* fallthrough */
1003                     case symbol_kind::S_block: // block
1004                         yylhs.value.emplace< UScriptStatementList* >();
1005                         break;
1006 
1007                     case symbol_kind::S_FLOAT: // FLOAT
1008                         yylhs.value.emplace< float >();
1009                         break;
1010                     case symbol_kind::S_NUMBER: // NUMBER
1011                         yylhs.value.emplace< int >();
1012                         break;
1013                     case symbol_kind::S_VAR: // VAR
1014                         /* fallthrough */
1015                     case symbol_kind::S_FUNCTION: // FUNCTION
1016                         /* fallthrough */
1017                     case symbol_kind::S_GLOBAL: // GLOBAL
1018                         /* fallthrough */
1019                     case symbol_kind::S_FOR: // FOR
1020                         /* fallthrough */
1021                     case symbol_kind::S_WHILE: // WHILE
1022                         /* fallthrough */
1023                     case symbol_kind::S_IF: // IF
1024                         /* fallthrough */
1025                     case symbol_kind::S_ELSE: // ELSE
1026                         /* fallthrough */
1027                     case symbol_kind::S_ADD: // ADD
1028                         /* fallthrough */
1029                     case symbol_kind::S_SUB: // SUB
1030                         /* fallthrough */
1031                     case symbol_kind::S_MUL: // MUL
1032                         /* fallthrough */
1033                     case symbol_kind::S_DIV: // DIV
1034                         /* fallthrough */
1035                     case symbol_kind::S_ASSIGN: // ASSIGN
1036                         /* fallthrough */
1037                     case symbol_kind::S_AND: // AND
1038                         /* fallthrough */
1039                     case symbol_kind::S_OR: // OR
1040                         /* fallthrough */
1041                     case symbol_kind::S_EQ: // EQ
1042                         /* fallthrough */
1043                     case symbol_kind::S_NE: // NE
1044                         /* fallthrough */
1045                     case symbol_kind::S_GT: // GT
1046                         /* fallthrough */
1047                     case symbol_kind::S_GE: // GE
1048                         /* fallthrough */
1049                     case symbol_kind::S_LT: // LT
1050                         /* fallthrough */
1051                     case symbol_kind::S_LE: // LE
1052                         /* fallthrough */
1053                     case symbol_kind::S_LP: // LP
1054                         /* fallthrough */
1055                     case symbol_kind::S_RP: // RP
1056                         /* fallthrough */
1057                     case symbol_kind::S_LC: // LC
1058                         /* fallthrough */
1059                     case symbol_kind::S_RC: // RC
1060                         /* fallthrough */
1061                     case symbol_kind::S_SEMICOLON: // SEMICOLON
1062                         /* fallthrough */
1063                     case symbol_kind::S_IDENTIFIER: // IDENTIFIER
1064                         /* fallthrough */
1065                     case symbol_kind::S_BREAK: // BREAK
1066                         /* fallthrough */
1067                     case symbol_kind::S_CONTINUE: // CONTINUE
1068                         /* fallthrough */
1069                     case symbol_kind::S_RETURN: // RETURN
1070                         /* fallthrough */
1071                     case symbol_kind::S_COMMA: // COMMA
1072                         /* fallthrough */
1073                     case symbol_kind::S_STRING: // STRING
1074                         yylhs.value.emplace< string >();
1075                         break;
1076 
1077                     default:
1078                         break;
1079                 }
1080 
1081                 // Default location.
1082                 {
1083                     stack_type::slice range (yystack_, yylen);
1084                     YYLLOC_DEFAULT (yylhs.location, range, yylen);
1085                     yyerror_range[1].location = yylhs.location;
1086                 }
1087                 // Perform the reduction.
1088                 YY_REDUCE_PRINT (yyn);
1089 #if YY_EXCEPTIONS
1090                 try
1091 #endif // YY_EXCEPTIONS
1092                 {
1093                     switch (yyn) {
1094                         case 4: { // definition_or_statement: function_definition
1095                             interpreter->AddFunction(yystack_[0].value.as <ScriptFunction*>());
1096                             break;
1097                         }
1098                         case 5: { // definition_or_statement: statement
1099                             interpreter->AddStatement(yystack_[0].value.as < UScriptStatement* >());
1100                             break;
1101                         }
1102                         case 6: { // function_definition: FUNCTION IDENTIFIER LP arglist RP block
1103                             yylhs.value.as<ScriptFunction*>() = ScriptFunction::CreateInstance(
1104                                 yystack_[4].value.as<string>(),
1105                                 yystack_[2].value.as<ScriptParams*>(),
1106                                 yystack_[0].value.as < UScriptStatementList* >());
1107                             break;
1108                         }
1109                         case 7: { // function_definition: FUNCTION IDENTIFIER LP RP block
1110                             yylhs.value.as<ScriptFunction*>() = ScriptFunction::CreateInstance(
1111                                 yystack_[3].value.as<string>(),
1112                                 nullptr, yystack_[0].value.as<UScriptStatementList*>());
1113                             break;
1114                         }
1115                         case 8: { // statement: expression_statement
1116                             yylhs.value.as<UScriptStatement*>() = yystack_[0].value.as<UScriptStatement*>();
1117                             break;
1118                         }
1119 
1120                         case 9: { // statement: for_statement
1121                             yylhs.value.as<UScriptStatement*>() = yystack_[0].value.as<UScriptStatement*>();
1122                             break;
1123                         }
1124                         case 10: { // statement: while_statement
1125                             yylhs.value.as<UScriptStatement*>() = yystack_[0].value.as<UScriptStatement*>();
1126                             break;
1127                         }
1128                         case 11: { // statement: if_statement
1129                             yylhs.value.as<UScriptStatement*>() = yystack_[0].value.as<UScriptStatement*>();
1130                             break;
1131                         }
1132                         case 12: { // statement: break_statement
1133                             yylhs.value.as<UScriptStatement*>() = yystack_[0].value.as<UScriptStatement*>();
1134                             break;
1135                         }
1136                         case 13: { // statement: continue_statement
1137                             yylhs.value.as<UScriptStatement*>() = yystack_[0].value.as <UScriptStatement*>();
1138                             break;
1139                         }
1140                         case 14: { // statement: return_statement
1141                             yylhs.value.as<UScriptStatement*>() = yystack_[0].value.as <UScriptStatement*>();
1142                             break;
1143                         }
1144                         case 15: { // expression_statement: expression SEMICOLON
1145                             yylhs.value.as<UScriptStatement*>() =
1146                                 UScriptStatement::CreateExpressionStatement(
1147                                 yystack_[1].value.as<UScriptExpression*>());
1148                             break;
1149                         }
1150                         case 16: { // expression: value_expression
1151                             yylhs.value.as<UScriptExpression*>() = yystack_[0].value.as<UScriptExpression*>();
1152                             break;
1153                         }
1154                         case 17: { // expression: IDENTIFIER ASSIGN expression
1155                             yylhs.value.as<UScriptExpression*>() = AssignExpression::CreateExpression(
1156                                 yystack_[2].value.as<string>(), yystack_[0].value.as<UScriptExpression*>());
1157                             break;
1158                         }
1159                         case 18: { // expression: IDENTIFIER COMMA IDENTIFIER ASSIGN expression
1160                             yylhs.value.as<UScriptExpression*>() = AssignExpression::CreateExpression(
1161                                 yystack_[4].value.as<string>(), yystack_[0].value.as <UScriptExpression*>());
1162                             AssignExpression::AddIdentifier(yylhs.value.as<UScriptExpression*>(),
1163                                 yystack_[2].value.as<string>());
1164                             break;
1165                         }
1166                         case 19: { // expression: IDENTIFIER COMMA IDENTIFIER COMMA IDENTIFIER ASSIGN expression
1167                             yylhs.value.as<UScriptExpression*>() = AssignExpression::CreateExpression(
1168                                 yystack_[6].value.as<string>(), yystack_[0].value.as<UScriptExpression*>());
1169                             AssignExpression::AddIdentifier(yylhs.value.as<UScriptExpression*>(),
1170                                 yystack_[4].value.as<string>());
1171                             AssignExpression::AddIdentifier(yylhs.value.as<UScriptExpression*>(),
1172                                 yystack_[2].value.as<string>());
1173                             break;
1174                         }
1175                         case 20: {
1176                              // expression: IDENTIFIER COMMA IDENTIFIER COMMA IDENTIFIER
1177                              // COMMA IDENTIFIER ASSIGN expression
1178                             yylhs.value.as<UScriptExpression*>() = AssignExpression::CreateExpression(
1179                                 yystack_[8].value.as<string>(), yystack_[0].value.as<UScriptExpression*>());
1180                             AssignExpression::AddIdentifier(yylhs.value.as<UScriptExpression*>(),
1181                                 yystack_[6].value.as<string>());
1182                             AssignExpression::AddIdentifier(yylhs.value.as<UScriptExpression*>(),
1183                                 yystack_[4].value.as<string>());
1184                             AssignExpression::AddIdentifier(yylhs.value.as <UScriptExpression*>(),
1185                                 yystack_[2].value.as<string>());
1186                             break;
1187                         }
1188                         case 21: { // value_expression: compare_expression
1189                             yylhs.value.as<UScriptExpression*>() = yystack_[0].value.as <UScriptExpression*>();
1190                             break;
1191                         }
1192                         case 22: { // value_expression: value_expression EQ compare_expression
1193                             yylhs.value.as<UScriptExpression*>() = BinaryExpression::CreateExpression(
1194                                 UScriptExpression::EQ_OPERATOR,
1195                                 yystack_[2].value.as<UScriptExpression*>(),
1196                                 yystack_[0].value.as<UScriptExpression*>());
1197                             break;
1198                         }
1199                         case 23: { // value_expression: value_expression NE compare_expression
1200                              yylhs.value.as<UScriptExpression*>() = BinaryExpression::CreateExpression(
1201                                 UScriptExpression::NE_OPERATOR,
1202                                 yystack_[2].value.as<UScriptExpression*>(),
1203                                 yystack_[0].value.as<UScriptExpression*>());
1204                             break;
1205                         }
1206                         case 24: { // value_expression: value_expression AND compare_expression
1207                             yylhs.value.as<UScriptExpression*>() = BinaryExpression::CreateExpression(
1208                                 UScriptExpression::AND_OPERATOR,
1209                                 yystack_[2].value.as<UScriptExpression*>(),
1210                                 yystack_[0].value.as<UScriptExpression*>());
1211                             break;
1212                         }
1213                         case 25: { // value_expression: value_expression OR compare_expression
1214                             yylhs.value.as<UScriptExpression*>() = BinaryExpression::CreateExpression(
1215                                 UScriptExpression::OR_OPERATOR,
1216                                 yystack_[2].value.as<UScriptExpression*>(),
1217                                 yystack_[0].value.as<UScriptExpression*>());
1218                             break;
1219                         }
1220                         case 26: { // compare_expression: add_sub_expression
1221                             yylhs.value.as<UScriptExpression*>() = yystack_[0].value.as<UScriptExpression*>();
1222                             break;
1223                         }
1224                         case 27: { // compare_expression: compare_expression GT add_sub_expression
1225                             yylhs.value.as<UScriptExpression*>() = BinaryExpression::CreateExpression(
1226                                 UScriptExpression::GT_OPERATOR,
1227                                 yystack_[2].value.as<UScriptExpression*>(),
1228                                 yystack_[0].value.as<UScriptExpression*>());
1229                             break;
1230                         }
1231                         case 28: { // compare_expression: compare_expression GE add_sub_expression
1232                             yylhs.value.as<UScriptExpression*>() = BinaryExpression::CreateExpression(
1233                                 UScriptExpression::GE_OPERATOR,
1234                                 yystack_[2].value.as<UScriptExpression*>(),
1235                                 yystack_[0].value.as<UScriptExpression*>());
1236                             break;
1237                         }
1238                         case 29: { // compare_expression: compare_expression LT add_sub_expression
1239                             yylhs.value.as<UScriptExpression*>() = BinaryExpression::CreateExpression(
1240                                 UScriptExpression::LT_OPERATOR,
1241                                 yystack_[2].value.as<UScriptExpression*>(),
1242                                 yystack_[0].value.as<UScriptExpression*>());
1243                             break;
1244                         }
1245                         case 30: { // compare_expression: compare_expression LE add_sub_expression
1246                             yylhs.value.as<UScriptExpression*>() = BinaryExpression::CreateExpression(
1247                                 UScriptExpression::LE_OPERATOR,
1248                                 yystack_[2].value.as<UScriptExpression*>(),
1249                                 yystack_[0].value.as<UScriptExpression*>());
1250                             break;
1251                         }
1252                         case 31: { // add_sub_expression: mul_div_expression
1253                             yylhs.value.as<UScriptExpression*>() = yystack_[0].value.as<UScriptExpression*>();
1254                             break;
1255                         }
1256                         case 32: { // add_sub_expression: add_sub_expression ADD mul_div_expression
1257                             yylhs.value.as<UScriptExpression*>() = BinaryExpression::CreateExpression(
1258                                 UScriptExpression::ADD_OPERATOR,
1259                                 yystack_[2].value.as<UScriptExpression*>(),
1260                                 yystack_[0].value.as<UScriptExpression*>());
1261                             break;
1262                         }
1263                         case 33: { // add_sub_expression: add_sub_expression SUB mul_div_expression
1264                             yylhs.value.as<UScriptExpression*>() = BinaryExpression::CreateExpression(
1265                                 UScriptExpression::SUB_OPERATOR,
1266                                 yystack_[2].value.as<UScriptExpression*>(),
1267                                 yystack_[0].value.as<UScriptExpression*>());
1268                             break;
1269                         }
1270                         case 34: { // mul_div_expression: primary_expression
1271                             yylhs.value.as< UScriptExpression*>() = yystack_[0].value.as<UScriptExpression*>();
1272                             break;
1273                         }
1274                         case 35: { // mul_div_expression: mul_div_expression DIV primary_expression
1275                             yylhs.value.as<UScriptExpression*>() = BinaryExpression::CreateExpression(
1276                                 UScriptExpression::DIV_OPERATOR,
1277                                 yystack_[2].value.as<UScriptExpression*>(),
1278                                 yystack_[0].value.as<UScriptExpression*>());
1279                             break;
1280                         }
1281                         case 36: { // mul_div_expression: mul_div_expression MUL primary_expression
1282                             yylhs.value.as<UScriptExpression*>() = BinaryExpression::CreateExpression(
1283                                 UScriptExpression::MUL_OPERATOR,
1284                                 yystack_[2].value.as<UScriptExpression*>(),
1285                                 yystack_[0].value.as<UScriptExpression*>());
1286                             break;
1287                         }
1288                         case 37: { // primary_expression: SUB primary_expression
1289                             yylhs.value.as<UScriptExpression*>() =yystack_[0].value.as<UScriptExpression*>();
1290                             break;
1291                         }
1292                         case 38: { // primary_expression: LP expression RP
1293                             yylhs.value.as<UScriptExpression*>() =yystack_[1].value.as<UScriptExpression*>();
1294                             break;
1295                         }
1296                         case 39: { // primary_expression: IDENTIFIER
1297                             yylhs.value.as<UScriptExpression*>() = IdentifierExpression::CreateExpression(
1298                                 yystack_[0].value.as < string >());
1299                             break;
1300                         }
1301                         case 40: { // primary_expression: STRING
1302                             yylhs.value.as< UScriptExpression* >() = StringExpression::CreateExpression(
1303                                 yystack_[0].value.as<string>());
1304                             break;
1305                         }
1306                         case 41: { // primary_expression: NUMBER
1307                             yylhs.value.as<UScriptExpression*>() = IntegerExpression::CreateExpression(
1308                                 yystack_[0].value.as<int>());
1309                             break;
1310                         }
1311                         case 42: { // primary_expression: FLOAT
1312                             yylhs.value.as<UScriptExpression*>() = FloatExpression::CreateExpression(
1313                                 yystack_[0].value.as<float>());
1314                             break;
1315                         }
1316                         case 43: { // primary_expression: IDENTIFIER LP RP
1317                             yylhs.value.as<UScriptExpression*>() = FunctionCallExpression::CreateExpression(
1318                                 yystack_[2].value.as<string>(), nullptr);
1319                             break;
1320                         }
1321                         case 44: { // primary_expression: IDENTIFIER LP arglist RP
1322                             yylhs.value.as<UScriptExpression*>() = FunctionCallExpression::CreateExpression(
1323                                 yystack_[3].value.as<string>(), yystack_[1].value.as<ScriptParams*>());
1324                             break;
1325                         }
1326                         case 45: { // statement_list: statement_list statement
1327                             yystack_[1].value.as<UScriptStatementList*>()->AddScriptStatement(
1328                                 yystack_[0].value.as < UScriptStatement* >());
1329                             yylhs.value.as <UScriptStatementList*>() = yystack_[1].value.as<UScriptStatementList*>();
1330                             break;
1331                         }
1332                         case 46: { // statement_list: statement
1333                             yylhs.value.as<UScriptStatementList*>() = UScriptStatementList::CreateInstance(
1334                                 yystack_[0].value.as<UScriptStatement*>());
1335                             break;
1336                         }
1337                         case 47: { // block: LC RC
1338                             yylhs.value.as<UScriptStatementList*>()= nullptr;
1339                             break;
1340                         }
1341                         case 48: { // block: LC statement_list RC
1342                             yylhs.value.as<UScriptStatementList*>() = yystack_[1].value.as<UScriptStatementList*>();
1343                             break;
1344                         }
1345                         case 49: { // arglist: arglist COMMA arg
1346                             yylhs.value.as<ScriptParams*>() = ScriptParams::AddParams(
1347                                 yystack_[2].value.as<ScriptParams*>(), yystack_[0].value.as<UScriptExpression*>());
1348                             break;
1349                         }
1350                         case 50: { // arglist: arg
1351                             yylhs.value.as<ScriptParams*>() = ScriptParams::CreateParams(
1352                                 yystack_[0].value.as<UScriptExpression*>());
1353                             break;
1354                         }
1355                         case 51: { // arg: value_expression
1356                             yylhs.value.as<UScriptExpression*>() = yystack_[0].value.as<UScriptExpression*>();
1357                             break;
1358                         }
1359                         case 52: { // expression_option: %empty
1360                             yylhs.value.as<UScriptExpression*>() = nullptr;
1361                             break;
1362                         }
1363                         case 53: { // expression_option: expression
1364                             yylhs.value.as<UScriptExpression*>() = yystack_[0].value.as<UScriptExpression*>();
1365                             break;
1366                         }
1367                         case 54: {
1368                              // for_statement: FOR LP expression_option SEMICOLON
1369                              // expression_option SEMICOLON expression_option RP block
1370                             yylhs.value.as<UScriptStatement*>() = UScriptStatement::CreateForStatement(
1371                                 yystack_[6].value.as<UScriptExpression*>(),
1372                                 yystack_[4].value.as<UScriptExpression*>(),
1373                                 yystack_[2].value.as<UScriptExpression*>(),
1374                                 yystack_[0].value.as<UScriptStatementList*>());
1375                             break;
1376                         }
1377                         case 55: { // while_statement: WHILE LP expression_option RP block
1378                             yylhs.value.as<UScriptStatement*>() = UScriptStatement::CreateWhileStatement(
1379                                 yystack_[2].value.as<UScriptExpression*>(),
1380                                 (UScriptStatementList*)yystack_[0].value.as<UScriptStatementList*>());
1381                             break;
1382                         }
1383                         case 56: { // if_statement: IF LP expression RP block
1384                             yylhs.value.as<UScriptStatement*>() = UScriptStatement::CreateIfStatement(
1385                                 yystack_[2].value.as<UScriptExpression*>(),
1386                                 yystack_[0].value.as<UScriptStatementList*>());
1387                             break;
1388                         }
1389                         case 57: { // if_statement: IF LP expression RP block ELSE if_statement
1390                             yylhs.value.as<UScriptStatement*>() = UScriptStatement::CreateIfStatement(
1391                                 yystack_[4].value.as<UScriptExpression*>(),
1392                                 yystack_[2].value.as<UScriptStatementList*>(),
1393                                 nullptr, yystack_[0].value.as<UScriptStatement*>());
1394                             break;
1395                         }
1396                         case 58: { // if_statement: IF LP expression RP block ELSE block
1397                             yylhs.value.as<UScriptStatement*>() = UScriptStatement::CreateIfStatement(
1398                                 yystack_[4].value.as<UScriptExpression*>(),
1399                                 yystack_[2].value.as<UScriptStatementList*>(),
1400                                 yystack_[0].value.as<UScriptStatementList*>());
1401                             break;
1402                         }
1403                         case 59: { // break_statement: BREAK SEMICOLON
1404                             yylhs.value.as<UScriptStatement*>() = UScriptStatement::CreateStatement(
1405                                 UScriptStatement::STATEMENT_TYPE_BREAK);
1406                             break;
1407                         }
1408                         case 60: { // continue_statement: CONTINUE SEMICOLON
1409                             // $$=create_Statement(STATEMENT_TYPE_CONTINUE);
1410                             yylhs.value.as<UScriptStatement*>() = UScriptStatement::CreateStatement(
1411                                 UScriptStatement::STATEMENT_TYPE_CONTINUE);
1412                             break;
1413                         }
1414                         case 61: { // return_statement: RETURN arglist SEMICOLON
1415                             yylhs.value.as<UScriptStatement*>() = UScriptReturnStatement::CreateStatement(
1416                                 yystack_[1].value.as<ScriptParams*>());
1417                             break;
1418                         }
1419                         case 62: { // return_statement: RETURN SEMICOLON
1420                             yylhs.value.as< UScriptStatement*>() = UScriptReturnStatement::CreateStatement(nullptr);
1421                             break;
1422                         }
1423                         default:
1424                             break;
1425                     }
1426                 }
1427 #if YY_EXCEPTIONS
1428                 catch (const syntax_error& yyexc) {
1429                     YYCDEBUG << "Caught exception: " << yyexc.what()<< '\n';
1430                     error (yyexc);
1431                     YYERROR;
1432                 }
1433 #endif // YY_EXCEPTIONS
1434                 YY_SYMBOL_PRINT("-> $$ =", yylhs);
1435                 yypop_(yylen);
1436                 yylen = 0;
1437                 // Shift the result of the reduction.
1438                 yypush_(YY_NULLPTR, YY_MOVE (yylhs));
1439             }
1440             goto yynewstate;
1441 
1442             /*--------------------------------------.
1443             | yyerrlab -- here on detecting error.  |
1444             `--------------------------------------*/
1445 yyerrlab:
1446             // If not already recovering from an error, report this error.
1447             if (!yyerrstatus_) {
1448                 ++yynerrs_;
1449                 context yyctx (*this, yyla);
1450                 std::string msg = yysyntax_error_ (yyctx);
1451                 error (yyla.location, YY_MOVE (msg));
1452             }
1453 
1454             yyerror_range[1].location = yyla.location;
1455             if (yyerrstatus_ == 3) {
1456                 /* If just tried and failed to reuse lookahead token after an error, discard it.  */
1457                 // Return failure if at end of input.
1458                 if (yyla.kind ()== symbol_kind::S_YYEOF) {
1459                     YYABORT;
1460                 } else if (!yyla.empty ()) {
1461                     yy_destroy_ ("Error: discarding", yyla);
1462                     yyla.clear ();
1463                }
1464             }
1465             // Else will try to reuse lookahead token after shifting the error token.
1466             goto yyerrlab1;
1467             /*---------------------------------------------------.
1468             | yyerrorlab -- error raised explicitly by YYERROR.  |
1469             `---------------------------------------------------*/
1470 yyerrorlab:
1471             /* Pacify compilers when the user code never invokes YYERROR and
1472               the label yyerrorlab therefore never appears in user code.  */
1473             if (false) {
1474                 YYERROR;
1475             }
1476 
1477             /* Do not reclaim the symbols of the rule whose action triggered this YYERROR.  */
1478             yypop_(yylen);
1479             yylen = 0;
1480             YY_STACK_PRINT();
1481             goto yyerrlab1;
1482             /*-------------------------------------------------------------.
1483             | yyerrlab1 -- common code for both syntax error and YYERROR.  |
1484             `-------------------------------------------------------------*/
1485 yyerrlab1:
1486             yyerrstatus_ = 3;   // Each real token shifted decrements this.
1487             // Pop stack until we find a state that shifts the error token.
1488             for (;;) {
1489                 yyn = yypact_[+yystack_[0].state];
1490                 if (!yy_pact_value_is_default_(yyn)) {
1491                     yyn += symbol_kind::S_YYerror;
1492                     if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == symbol_kind::S_YYerror) {
1493                         yyn = yytable_[yyn];
1494                         if (0 < yyn) {
1495                             break;
1496                         }
1497                     }
1498                 }
1499 
1500                 // Pop the current state because it cannot handle the error token.
1501                 if (yystack_.size()== 1) {
1502                     YYABORT;
1503                 }
1504                 yyerror_range[1].location = yystack_[0].location;
1505                 yy_destroy_("Error: popping", yystack_[0]);
1506                 yypop_();
1507                 YY_STACK_PRINT();
1508             }
1509 
1510             {
1511                 stack_symbol_type error_token;
1512                 yyerror_range[2].location = yyla.location;
1513                 YYLLOC_DEFAULT (error_token.location, yyerror_range, 2);
1514 
1515                 // Shift the error token.
1516                 error_token.state = state_type (yyn);
1517                 yypush_ ("Shifting", YY_MOVE (error_token));
1518             }
1519             goto yynewstate;
1520             /*-------------------------------------.
1521             | yyacceptlab -- YYACCEPT comes here.  |
1522             `-------------------------------------*/
1523 yyacceptlab:
1524             yyresult = 0;
1525             goto yyreturn;
1526             /*-----------------------------------.
1527             | yyabortlab -- YYABORT comes here.  |
1528             `-----------------------------------*/
1529 yyabortlab:
1530             yyresult = 1;
1531             goto yyreturn;
1532 
1533             /*-----------------------------------------------------.
1534             | yyreturn -- parsing is finished, return the result.  |
1535             `-----------------------------------------------------*/
1536 yyreturn:
1537             if (!yyla.empty()) {
1538                 yy_destroy_("Cleanup: discarding lookahead", yyla);
1539             }
1540             /* Do not reclaim the symbols of the rule whose action triggered this YYABORT or YYACCEPT.  */
1541             yypop_ (yylen);
1542             YY_STACK_PRINT ();
1543             while (1 < yystack_.size()) {
1544                 yy_destroy_("Cleanup: popping", yystack_[0]);
1545                 yypop_();
1546             }
1547             return yyresult;
1548         }
1549 #if YY_EXCEPTIONS
1550         catch (...) {
1551             YYCDEBUG << "Exception caught: cleaning lookahead and stack\n";
1552             // Do not try to display the values of the reclaimed symbols,
1553             // as their printers might throw an exception.
1554             if (!yyla.empty ()) {
1555                     yy_destroy_ (YY_NULLPTR, yyla);
1556             }
1557             while (1 < yystack_.size ()) {
1558                 yy_destroy_ (YY_NULLPTR, yystack_[0]);
1559                 yypop_ ();
1560             }
1561             throw;
1562         }
1563 #endif // YY_EXCEPTIONS
1564     }
1565 
error(const syntax_error & yyexc)1566     void Parser::error(const syntax_error& yyexc)
1567     {
1568         error(yyexc.location, yyexc.what());
1569     }
1570 
1571     /* Return YYSTR after stripping away unnecessary quotes and
1572        backslashes, so that it's suitable for yyerror.  The heuristic is
1573        that double-quoting is unnecessary unless the string contains an
1574        apostrophe, a comma, or backslash (other than backslash-backslash).
1575        YYSTR is taken from yytname.  */
yytnamerr_(const char * yystr)1576     std::string Parser::yytnamerr_(const char *yystr)
1577     {
1578         if (*yystr == '"') {
1579             std::string yyr;
1580             char const *yyp = yystr;
1581             for (;;)
1582                 switch (*++yyp) {
1583                     case '\'':
1584                     /* fallthrough */
1585                     case ',':
1586                         goto do_not_strip_quotes;
1587 
1588                     case '\\':
1589                         if (*++yyp != '\\') {
1590                             goto do_not_strip_quotes;
1591                         } else {
1592                             goto append;
1593                         }
1594 append:
1595                     default:
1596                         yyr += *yyp;
1597                         break;
1598 
1599                     case '"':
1600                         return yyr;
1601                 }
1602             do_not_strip_quotes: ;
1603         }
1604         return yystr;
1605     }
1606 
symbol_name(symbol_kind_type yysymbol)1607     std::string Parser::symbol_name(symbol_kind_type yysymbol)
1608     {
1609         return yytnamerr_(yytname_[yysymbol]);
1610     }
1611 
1612     //  Parser::context.
context(const Parser & yyparser,const symbol_type & yyla)1613     Parser::context::context(const  Parser &yyparser, const symbol_type &yyla)
1614         : yyparser_(yyparser), yyla_(yyla) {}
1615 
expected_tokens(symbol_kind_type yyarg[],int yyargn) const1616     int Parser::context::expected_tokens(symbol_kind_type yyarg[], int yyargn) const
1617     {
1618         // Actual number of expected tokens
1619         int yycount = 0;
1620 
1621         int yyn = yypact_[+yyparser_.yystack_[0].state];
1622         if (!yy_pact_value_is_default_(yyn)) {
1623         /* Start YYX at -YYN if negative to avoid negative indexes in
1624            YYCHECK.  In other words, skip the first -YYN actions for
1625            this state because they are default actions.  */
1626             int yyxbegin = yyn < 0 ? -yyn : 0;
1627             // Stay within bounds of both yycheck and yytname.
1628             int yychecklim = yylast_ - yyn + 1;
1629             int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1630             for (int yyx = yyxbegin; yyx < yyxend; ++yyx) {
1631                 if (yycheck_[yyx + yyn] == yyx && yyx != symbol_kind::S_YYerror &&
1632                     !yy_table_value_is_error_ (yytable_[yyx + yyn])) {
1633                     if (!yyarg) {
1634                         ++yycount;
1635                     } else if (yycount == yyargn) {
1636                         return 0;
1637                     } else {
1638                         yyarg[yycount++] = YY_CAST (symbol_kind_type, yyx);
1639                     }
1640                 }
1641             }
1642         }
1643 
1644         if (yyarg && yycount == 0 && 0 < yyargn) {
1645             yyarg[0] = symbol_kind::S_YYEMPTY;
1646         }
1647         return yycount;
1648     }
1649 
yy_syntax_error_arguments_(const context & yyctx,symbol_kind_type yyarg[],int yyargn) const1650     int Parser::yy_syntax_error_arguments_(const context& yyctx, symbol_kind_type yyarg[], int yyargn) const
1651     {
1652         /* There are many possibilities here to consider:
1653               - If this state is a consistent state with a default action, then
1654                   the only way this function was invoked is if the default action
1655                   is an error action.  In that case, don't check for expected
1656                   tokens because there are none.
1657               - The only way there can be no lookahead present (in yyla)is
1658                   if this state is a consistent state with a default action.
1659                   Thus, detecting the absence of a lookahead is sufficient to
1660                   determine that there is no unexpected or expected token to
1661                   report.  In that case, just report a simple "syntax error".
1662               - Don't assume there isn't a lookahead just because this state is
1663                   a consistent state with a default action.  There might have
1664                   been a previous inconsistent state, consistent state with a
1665                   non-default action, or user semantic action that manipulated
1666                   yyla.  (However, yyla is currently not documented for users.)
1667               - Of course, the expected token list depends on states to have
1668                   correct lookahead information, and it depends on the parser not
1669                   to perform extra reductions after fetching a lookahead from the
1670                   scanner and before detecting a syntax error.  Thus, state merging
1671                   (from LALR or IELR)and default reductions corrupt the expected
1672                   token list.  However, the list is correct for canonical LR with
1673                   one exception: it will still contain any token that will not be
1674                   accepted due to an error action in a later state.
1675         */
1676 
1677         if (!yyctx.lookahead ().empty()) {
1678             if (yyarg) {
1679                 yyarg[0] = yyctx.token();
1680             }
1681             int yyn = yyctx.expected_tokens(yyarg ? yyarg + 1 : yyarg, yyargn - 1);
1682             return yyn + 1;
1683         }
1684         return 0;
1685     }
1686 
1687     // Generate an error message.
yysyntax_error_(const context & yyctx) const1688     std::string Parser::yysyntax_error_(const context& yyctx) const
1689     {
1690         // Its maximum.
1691         enum { YYARGS_MAX = 5 };
1692         // Arguments of yyformat.
1693         symbol_kind_type yyarg[YYARGS_MAX];
1694         int yycount = yy_syntax_error_arguments_(yyctx, yyarg, YYARGS_MAX);
1695 
1696         char const* yyformat = YY_NULLPTR;
1697         switch (yycount) {
1698 #define YYCASE_(N, S)                        \
1699             case N:                               \
1700                 yyformat = S;                       \
1701                 break
1702             default: // Avoid compiler warnings.
1703                 YYCASE_ (0, YY_("syntax error"));
1704                 YYCASE_ (1, YY_("syntax error, unexpected %s"));
1705                 YYCASE_ (2, YY_("syntax error, unexpected %s, expecting %s"));
1706                 YYCASE_ (3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1707                 YYCASE_ (4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1708                 YYCASE_ (5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1709 #undef YYCASE_
1710         }
1711 
1712         std::string yyres;
1713         // Argument number.
1714         std::ptrdiff_t yyi = 0;
1715         for (char const* yyp = yyformat; *yyp; ++yyp)
1716             if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount) {
1717                 yyres += symbol_name (yyarg[yyi++]);
1718                 ++yyp;
1719             } else {
1720                 yyres += *yyp;
1721             }
1722         return yyres;
1723     }
1724 
1725     const signed char  Parser::yypact_ninf_ = -89;
1726     const signed char  Parser::yytable_ninf_ = -1;
1727     const short Parser::yypact_[] =
1728     {
1729         40, -89, -89, -11, -4, 16, 27, 99, 151, 29,
1730         15, 32, 74, -89, 5, -89, -89, -89, -89, 35,
1731         120, 148, 19, 54, -89, -89, -89, -89, -89, -89,
1732         -89, 33, 151, 151, 151, 41, -89, 56,  151, 130,
1733         59, -89, -89, -89, 120, -17, -89, -89, -89, -89,
1734         99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
1735         99, 99, 133, -89, 55, 64, 68, -89, -89, -89,
1736         0, -14, -89, 99, 148, 148, 148, 148, 19, 19,
1737         19, 19, 54, 54, -89, -89, 70, 13, 151, 70,
1738         70, -89, 151, 65, -89, 83, -89, 70, 76, -89,
1739         95, -89, -7, -89, -89, 117, -89, 151, -5, 151,
1740         77, -89, -89, 91, -89, -89, -89, 105, 70, 151,
1741         -89, -89
1742     };
1743 
1744     const signed char Parser::yydefact_[] =
1745     {
1746         0, 41, 42, 0, 0, 0, 0, 0, 0, 39,
1747         0, 0, 0, 40, 0, 2, 4, 5, 8, 0,
1748         16, 21, 26, 31, 34, 9, 10, 11, 12, 13,
1749         14, 0, 52, 52, 0, 39, 37, 0, 0, 0,
1750         0, 59, 60, 62, 51, 0, 50, 1, 3, 15,
1751         0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1752         0, 0, 0, 53, 0, 0, 0, 38, 17, 43,
1753         0, 0, 61, 0, 24, 25, 22, 23, 27, 28,
1754         29, 30, 32, 33, 36, 35, 0, 0, 52, 0,
1755         0, 44, 0, 0, 49, 0, 7, 0,  0, 55,
1756         56, 18, 0, 47, 46, 0, 6, 52, 0, 0,
1757         0, 48, 45, 0, 58, 57, 19, 0, 0, 0,
1758         54, 20
1759     };
1760 
1761     const short Parser::yypgoto_[] =
1762     {
1763         -89, -89, 109, -89, -88, -89, -8, -10, 128, 129,
1764         23, -3, -89, -29, -28, 51, -32, -89, -89, 21,
1765         -89, -89, -89
1766     };
1767 
1768     const signed char Parser::yydefgoto_[] =
1769     {
1770         -1, 14, 15, 16, 17, 18, 19, 20, 21, 22,
1771         23, 24, 105, 96, 45, 46, 64, 25, 26, 27,
1772         28, 29, 30
1773     };
1774 
1775     const signed char Parser::yytable_[] =
1776     {
1777         37, 65, 44, 92, 36, 47, 6, 104, 1, 2,
1778         109, 70, 3, 72, 4, 5, 6, 112, 73, 7,
1779         31, 93, 32, 95, 63, 63, 66, 91, 110, 44,
1780         68, 8, 58, 59, 87, 73, 9, 10, 11, 12,
1781         97, 13, 33, 1, 2, 41, 38, 3, 73, 4,
1782         5, 6, 44, 34, 7, 39, 98, 84, 85, 62,
1783         99, 100, 42, 44, 40, 49, 8, 39, 106, 60,
1784         61, 9, 10, 11, 12, 113, 13, 1, 2, 114,
1785         63, 82, 83, 67, 101, 88, 1, 2, 7, 120,
1786         71, 89, 4, 5, 6, 90, 102, 7, 95, 63,
1787         8, 116, 1, 2, 43, 35, 107, 108, 117, 8,
1788         13, 121, 103, 7, 9, 10, 11, 12, 118, 13,
1789         1, 2, 119, 48, 94, 8, 4, 5, 6, 115,
1790         35, 7, 0, 1, 2, 13, 1, 2, 50, 51,
1791         52, 53, 0, 8, 7, 0, 111, 7, 9, 10,
1792         11, 12, 0, 13, 1, 2, 8, 69, 0, 8,
1793         86, 35, 0, 0, 35, 7, 13, 0, 0, 13,
1794         54, 55, 56, 57, 0, 0, 0, 8, 74, 75,
1795         76, 77, 9, 78, 79, 80, 81, 13
1796     };
1797 
1798     const signed char Parser::yycheck_[] =
1799     {
1800         8, 33, 12, 17, 7, 0, 11, 95, 3, 4,
1801         17, 39, 7, 30, 9, 10, 11, 105, 35, 14,
1802         31, 35, 26, 28, 32, 33, 34, 27, 35, 39,
1803         38, 26, 13, 14, 62, 35, 31, 32, 33, 34,
1804         27, 36, 26, 3, 4, 30, 17, 7, 35, 9,
1805         10, 11, 62, 26, 14, 26, 88, 60, 61, 26,
1806         89, 90, 30, 73, 35, 30, 26, 26, 97, 15,
1807         16, 31, 32, 33, 34, 107, 36, 3, 4, 108,
1808         88, 58, 59, 27, 92, 30, 3, 4, 14, 118,
1809         31, 27, 9, 10, 11, 27, 31, 14, 28, 107,
1810         26, 109, 3, 4, 30, 31, 30, 12, 31, 26,
1811         36, 119, 29, 14, 31, 32, 33, 34, 27, 36,
1812         3,  4, 17, 14, 73, 26, 9, 10, 11, 108,
1813         31, 14, -1, 3, 4, 36, 3, 4, 18, 19,
1814         20, 21, -1, 26, 14, -1, 29, 14, 31, 32,
1815         33, 34, -1, 36, 3, 4, 26, 27, -1, 26,
1816         27, 31, -1, -1, 31, 14, 36, -1, -1, 36,
1817         22, 23, 24, 25, -1, -1, -1, 26, 50, 51,
1818         52, 53, 31, 54, 55, 56, 57, 36
1819     };
1820 
1821     const signed char Parser::yystos_[] =
1822     {
1823         0, 3, 4, 7, 9, 10, 11, 14, 26, 31,
1824         32, 33, 34, 36, 38, 39, 40, 41, 42, 43,
1825         44, 45, 46, 47, 48, 54, 55, 56, 57, 58,
1826         59, 31, 26, 26, 26, 31, 48, 43, 17, 26,
1827         35, 30, 30, 30, 44, 51, 52,  0, 39, 30,
1828         18, 19, 20, 21, 22, 23, 24, 25, 13, 14,
1829         15, 16, 26, 43, 53, 53, 43, 27, 43, 27,
1830         51, 31, 30, 35, 45, 45, 45, 45, 46, 46,
1831         46, 46, 47, 47, 48, 48, 27, 51, 30, 27,
1832         27, 27, 17, 35, 52, 28, 50, 27, 53, 50,
1833         50, 43, 31, 29, 41, 49, 50, 30, 12, 17,
1834         35, 29, 41, 53, 50, 56, 43, 31, 27, 17,
1835         50, 43
1836     };
1837 
1838     const signed char Parser::yyr1_[] =
1839     {
1840         0,  37, 38, 38, 39, 39, 40, 40, 41, 41,
1841         41, 41, 41, 41, 41, 42, 43, 43, 43, 43,
1842         43, 44, 44, 44, 44, 44, 45, 45, 45, 45,
1843         45, 46, 46, 46, 47, 47, 47, 48, 48, 48,
1844         48, 48, 48, 48, 48, 49, 49, 50, 50, 51,
1845         51, 52, 53, 53, 54, 55, 56, 56, 56, 57,
1846         58, 59, 59
1847     };
1848 
1849     const signed char Parser::yyr2_[] =
1850     {
1851         0, 2, 1, 2, 1, 1, 6, 5, 1, 1,
1852         1, 1, 1, 1, 1, 2, 1, 3, 5, 7,
1853         9, 1, 3, 3, 3, 3, 1, 3, 3, 3,
1854         3, 1, 3, 3, 1, 3, 3, 2, 3, 1,
1855         1, 1, 1, 3, 4, 2, 1, 2, 3, 3,
1856         1, 1, 0, 1, 9, 5, 5, 7, 7, 2,
1857         2, 3, 2
1858     };
1859 
1860 #if YYDEBUG || 1
1861     // YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1862     // First, the terminals, then, starting at \a YYNTOKENS, nonterminals.
1863     const char* const  Parser::yytname_[] =
1864     {
1865         "END", "error", "\"invalid token\"", "NUMBER", "FLOAT", "EOL", "VAR",
1866         "FUNCTION", "GLOBAL", "FOR", "WHILE", "IF", "ELSE", "ADD", "SUB", "MUL",
1867         "DIV", "ASSIGN", "AND", "OR", "EQ", "NE", "GT", "GE", "LT", "LE", "LP",
1868         "RP", "LC", "RC", "SEMICOLON", "IDENTIFIER", "BREAK", "CONTINUE",
1869         "RETURN", "COMMA", "STRING", "$accept", "translation_unit",
1870         "definition_or_statement", "function_definition", "statement",
1871         "expression_statement", "expression", "value_expression",
1872         "compare_expression", "add_sub_expression", "mul_div_expression",
1873         "primary_expression", "statement_list", "block", "arglist", "arg",
1874         "expression_option", "for_statement", "while_statement", "if_statement",
1875         "break_statement", "continue_statement", "return_statement", YY_NULLPTR
1876     };
1877 #endif
1878 
1879 #if YYDEBUG
1880     const short Parser::yyrline_[] =
1881     {
1882         0, 117, 117, 118, 120, 124, 129, 134, 139, 140,
1883         141, 142, 143, 144, 145, 147, 152, 153, 157, 162,
1884         168, 176, 177, 181, 185, 189, 194, 195, 199, 203,
1885         207, 212, 213, 217, 222, 223, 227, 232, 236, 240,
1886         244, 248, 252, 256, 260, 265, 270, 275, 279, 284,
1887         288, 293, 296, 299, 301, 306, 311, 315, 319, 324,
1888         329, 335, 339
1889     };
1890 
yy_stack_print_() const1891     void Parser::yy_stack_print_() const
1892     {
1893         *yycdebug_ << "Stack now";
1894         for (stack_type::const_iterator i = yystack_.begin (), i_end = yystack_.end ();
1895             i != i_end; ++i) {
1896             *yycdebug_ << ' ' << int (i->state);
1897         }
1898         *yycdebug_ << '\n';
1899     }
1900 
yy_reduce_print_(int yyrule) const1901     void Parser::yy_reduce_print_(int yyrule) const
1902     {
1903         int yylno = yyrline_[yyrule];
1904         int yynrhs = yyr2_[yyrule];
1905         // Print the symbols being reduced, and their result.
1906         *yycdebug_ << "Reducing stack by rule " << yyrule - 1
1907                               << " (line " << yylno << "):\n";
1908         // The symbols being reduced.
1909         for (int yyi = 0; yyi < yynrhs; yyi++) {
1910             YY_SYMBOL_PRINT ("   $" << yyi + 1 << " =",
1911                 yystack_[(yynrhs)- (yyi + 1)]);
1912         }
1913     }
1914 #endif // YYDEBUG
1915 
1916 } // uscript
1917 
1918