comparison Bison-Flex/CALC/Bison-Flex/calc-parser.cc @ 0:db40c85cad7a default tip

upload sample source
author nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
date Mon, 09 May 2011 03:11:59 +0900
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:db40c85cad7a
1 /* A Bison parser, made by GNU Bison 2.3. */
2
3 /* Skeleton implementation for Bison LALR(1) parsers in C++
4
5 Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
21
22 /* As a special exception, you may create a larger work that contains
23 part or all of the Bison parser skeleton and distribute that work
24 under terms of your choice, so long as that work isn't itself a
25 parser generator using the skeleton or a modified version thereof
26 as a parser skeleton. Alternatively, if you modify or redistribute
27 the parser skeleton itself, you may (at your option) remove this
28 special exception, which will cause the skeleton and the resulting
29 Bison output files to be licensed under the GNU General Public
30 License without this special exception.
31
32 This special exception was added by the Free Software Foundation in
33 version 2.2 of Bison. */
34
35
36 #include "calc-parser.hh"
37
38 /* User implementation prologue. */
39 #line 27 "calc-parser.yy"
40
41 #include "calc-driver.h"
42
43
44 /* Line 317 of lalr1.cc. */
45 #line 46 "calc-parser.cc"
46
47 #ifndef YY_
48 # if YYENABLE_NLS
49 # if ENABLE_NLS
50 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
51 # define YY_(msgid) dgettext ("bison-runtime", msgid)
52 # endif
53 # endif
54 # ifndef YY_
55 # define YY_(msgid) msgid
56 # endif
57 #endif
58
59 /* Suppress unused-variable warnings by "using" E. */
60 #define YYUSE(e) ((void) (e))
61
62 /* A pseudo ostream that takes yydebug_ into account. */
63 # define YYCDEBUG \
64 for (bool yydebugcond_ = yydebug_; yydebugcond_; yydebugcond_ = false) \
65 (*yycdebug_)
66
67 /* Enable debugging if requested. */
68 #if YYDEBUG
69
70 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
71 do { \
72 if (yydebug_) \
73 { \
74 *yycdebug_ << Title << ' '; \
75 yy_symbol_print_ ((Type), (Value), (Location)); \
76 *yycdebug_ << std::endl; \
77 } \
78 } while (false)
79
80 # define YY_REDUCE_PRINT(Rule) \
81 do { \
82 if (yydebug_) \
83 yy_reduce_print_ (Rule); \
84 } while (false)
85
86 # define YY_STACK_PRINT() \
87 do { \
88 if (yydebug_) \
89 yystack_print_ (); \
90 } while (false)
91
92 #else /* !YYDEBUG */
93
94 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
95 # define YY_REDUCE_PRINT(Rule)
96 # define YY_STACK_PRINT()
97
98 #endif /* !YYDEBUG */
99
100 #define YYACCEPT goto yyacceptlab
101 #define YYABORT goto yyabortlab
102 #define YYERROR goto yyerrorlab
103
104 namespace yy
105 {
106 #if YYERROR_VERBOSE
107
108 /* Return YYSTR after stripping away unnecessary quotes and
109 backslashes, so that it's suitable for yyerror. The heuristic is
110 that double-quoting is unnecessary unless the string contains an
111 apostrophe, a comma, or backslash (other than backslash-backslash).
112 YYSTR is taken from yytname. */
113 std::string
114 calc_parser::yytnamerr_ (const char *yystr)
115 {
116 if (*yystr == '"')
117 {
118 std::string yyr = "";
119 char const *yyp = yystr;
120
121 for (;;)
122 switch (*++yyp)
123 {
124 case '\'':
125 case ',':
126 goto do_not_strip_quotes;
127
128 case '\\':
129 if (*++yyp != '\\')
130 goto do_not_strip_quotes;
131 /* Fall through. */
132 default:
133 yyr += *yyp;
134 break;
135
136 case '"':
137 return yyr;
138 }
139 do_not_strip_quotes: ;
140 }
141
142 return yystr;
143 }
144
145 #endif
146
147 /// Build a parser object.
148 calc_parser::calc_parser (calc_driver& driver_yyarg)
149 : yydebug_ (false),
150 yycdebug_ (&std::cerr),
151 driver (driver_yyarg)
152 {
153 }
154
155 calc_parser::~calc_parser ()
156 {
157 }
158
159 #if YYDEBUG
160 /*--------------------------------.
161 | Print this symbol on YYOUTPUT. |
162 `--------------------------------*/
163
164 inline void
165 calc_parser::yy_symbol_value_print_ (int yytype,
166 const semantic_type* yyvaluep, const location_type* yylocationp)
167 {
168 YYUSE (yylocationp);
169 YYUSE (yyvaluep);
170 switch (yytype)
171 {
172 default:
173 break;
174 }
175 }
176
177
178 void
179 calc_parser::yy_symbol_print_ (int yytype,
180 const semantic_type* yyvaluep, const location_type* yylocationp)
181 {
182 *yycdebug_ << (yytype < yyntokens_ ? "token" : "nterm")
183 << ' ' << yytname_[yytype] << " ("
184 << *yylocationp << ": ";
185 yy_symbol_value_print_ (yytype, yyvaluep, yylocationp);
186 *yycdebug_ << ')';
187 }
188 #endif /* ! YYDEBUG */
189
190 void
191 calc_parser::yydestruct_ (const char* yymsg,
192 int yytype, semantic_type* yyvaluep, location_type* yylocationp)
193 {
194 YYUSE (yylocationp);
195 YYUSE (yymsg);
196 YYUSE (yyvaluep);
197
198 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
199
200 switch (yytype)
201 {
202 case 4: /* "\"identifier\"" */
203 #line 39 "calc-parser.yy"
204 { delete (yyvaluep->sval); };
205 #line 206 "calc-parser.cc"
206 break;
207 case 19: /* "expr" */
208 #line 40 "calc-parser.yy"
209 { delete (yyvaluep->expr); };
210 #line 211 "calc-parser.cc"
211 break;
212
213 default:
214 break;
215 }
216 }
217
218 void
219 calc_parser::yypop_ (unsigned int n)
220 {
221 yystate_stack_.pop (n);
222 yysemantic_stack_.pop (n);
223 yylocation_stack_.pop (n);
224 }
225
226 std::ostream&
227 calc_parser::debug_stream () const
228 {
229 return *yycdebug_;
230 }
231
232 void
233 calc_parser::set_debug_stream (std::ostream& o)
234 {
235 yycdebug_ = &o;
236 }
237
238
239 calc_parser::debug_level_type
240 calc_parser::debug_level () const
241 {
242 return yydebug_;
243 }
244
245 void
246 calc_parser::set_debug_level (debug_level_type l)
247 {
248 yydebug_ = l;
249 }
250
251
252 int
253 calc_parser::parse ()
254 {
255 /// Look-ahead and look-ahead in internal form.
256 int yychar = yyempty_;
257 int yytoken = 0;
258
259 /* State. */
260 int yyn;
261 int yylen = 0;
262 int yystate = 0;
263
264 /* Error handling. */
265 int yynerrs_ = 0;
266 int yyerrstatus_ = 0;
267
268 /// Semantic value of the look-ahead.
269 semantic_type yylval;
270 /// Location of the look-ahead.
271 location_type yylloc;
272 /// The locations where the error started and ended.
273 location yyerror_range[2];
274
275 /// $$.
276 semantic_type yyval;
277 /// @$.
278 location_type yyloc;
279
280 int yyresult;
281
282 YYCDEBUG << "Starting parse" << std::endl;
283
284
285 /* Initialize the stacks. The initial state will be pushed in
286 yynewstate, since the latter expects the semantical and the
287 location values to have been already stored, initialize these
288 stacks with a primary value. */
289 yystate_stack_ = state_stack_type (0);
290 yysemantic_stack_ = semantic_stack_type (0);
291 yylocation_stack_ = location_stack_type (0);
292 yysemantic_stack_.push (yylval);
293 yylocation_stack_.push (yylloc);
294
295 /* New state. */
296 yynewstate:
297 yystate_stack_.push (yystate);
298 YYCDEBUG << "Entering state " << yystate << std::endl;
299 goto yybackup;
300
301 /* Backup. */
302 yybackup:
303
304 /* Try to take a decision without look-ahead. */
305 yyn = yypact_[yystate];
306 if (yyn == yypact_ninf_)
307 goto yydefault;
308
309 /* Read a look-ahead token. */
310 if (yychar == yyempty_)
311 {
312 YYCDEBUG << "Reading a token: ";
313 yychar = yylex (&yylval, driver);
314 }
315
316
317 /* Convert token to internal form. */
318 if (yychar <= yyeof_)
319 {
320 yychar = yytoken = yyeof_;
321 YYCDEBUG << "Now at end of input." << std::endl;
322 }
323 else
324 {
325 yytoken = yytranslate_ (yychar);
326 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
327 }
328
329 /* If the proper action on seeing token YYTOKEN is to reduce or to
330 detect an error, take that action. */
331 yyn += yytoken;
332 if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yytoken)
333 goto yydefault;
334
335 /* Reduce or error. */
336 yyn = yytable_[yyn];
337 if (yyn <= 0)
338 {
339 if (yyn == 0 || yyn == yytable_ninf_)
340 goto yyerrlab;
341 yyn = -yyn;
342 goto yyreduce;
343 }
344
345 /* Accept? */
346 if (yyn == yyfinal_)
347 goto yyacceptlab;
348
349 /* Shift the look-ahead token. */
350 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
351
352 /* Discard the token being shifted unless it is eof. */
353 if (yychar != yyeof_)
354 yychar = yyempty_;
355
356 yysemantic_stack_.push (yylval);
357 yylocation_stack_.push (yylloc);
358
359 /* Count tokens shifted since error; after three, turn off error
360 status. */
361 if (yyerrstatus_)
362 --yyerrstatus_;
363
364 yystate = yyn;
365 goto yynewstate;
366
367 /*-----------------------------------------------------------.
368 | yydefault -- do the default action for the current state. |
369 `-----------------------------------------------------------*/
370 yydefault:
371 yyn = yydefact_[yystate];
372 if (yyn == 0)
373 goto yyerrlab;
374 goto yyreduce;
375
376 /*-----------------------------.
377 | yyreduce -- Do a reduction. |
378 `-----------------------------*/
379 yyreduce:
380 yylen = yyr2_[yyn];
381 /* If YYLEN is nonzero, implement the default value of the action:
382 `$$ = $1'. Otherwise, use the top of the stack.
383
384 Otherwise, the following line sets YYVAL to garbage.
385 This behavior is undocumented and Bison
386 users should not rely upon it. */
387 if (yylen)
388 yyval = yysemantic_stack_[yylen - 1];
389 else
390 yyval = yysemantic_stack_[0];
391
392 {
393 slice<location_type, location_stack_type> slice (yylocation_stack_, yylen);
394 YYLLOC_DEFAULT (yyloc, slice, yylen);
395 }
396 YY_REDUCE_PRINT (yyn);
397 switch (yyn)
398 {
399 case 4:
400 #line 52 "calc-parser.yy"
401 { driver.assign((yysemantic_stack_[(4) - (1)].sval), (yysemantic_stack_[(4) - (3)].expr)); ;}
402 break;
403
404 case 5:
405 #line 53 "calc-parser.yy"
406 { driver.print((yysemantic_stack_[(3) - (2)].expr)); ;}
407 break;
408
409 case 6:
410 #line 54 "calc-parser.yy"
411 { driver.list(); ;}
412 break;
413
414 case 7:
415 #line 57 "calc-parser.yy"
416 { (yyval.expr) = new cnode(OP_MINUS, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;}
417 break;
418
419 case 8:
420 #line 58 "calc-parser.yy"
421 { (yyval.expr) = new cnode(OP_PLUS, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;}
422 break;
423
424 case 9:
425 #line 59 "calc-parser.yy"
426 { (yyval.expr) = new cnode(OP_TIMES, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;}
427 break;
428
429 case 10:
430 #line 60 "calc-parser.yy"
431 { (yyval.expr) = new cnode(OP_DIVIDE, (yysemantic_stack_[(3) - (1)].expr), (yysemantic_stack_[(3) - (3)].expr)); ;}
432 break;
433
434 case 11:
435 #line 61 "calc-parser.yy"
436 { (yyval.expr) = new cnode(OP_NEG, (yysemantic_stack_[(2) - (2)].expr)); ;}
437 break;
438
439 case 12:
440 #line 62 "calc-parser.yy"
441 { (yyval.expr) = (yysemantic_stack_[(3) - (2)].expr); ;}
442 break;
443
444 case 13:
445 #line 63 "calc-parser.yy"
446 { (yyval.expr) = new cnode(OP_VALUE, (yysemantic_stack_[(1) - (1)].sval)); ;}
447 break;
448
449 case 14:
450 #line 64 "calc-parser.yy"
451 { (yyval.expr) = new cnode(OP_CONST, (yysemantic_stack_[(1) - (1)].ival)); ;}
452 break;
453
454
455 /* Line 675 of lalr1.cc. */
456 #line 457 "calc-parser.cc"
457 default: break;
458 }
459 YY_SYMBOL_PRINT ("-> $$ =", yyr1_[yyn], &yyval, &yyloc);
460
461 yypop_ (yylen);
462 yylen = 0;
463 YY_STACK_PRINT ();
464
465 yysemantic_stack_.push (yyval);
466 yylocation_stack_.push (yyloc);
467
468 /* Shift the result of the reduction. */
469 yyn = yyr1_[yyn];
470 yystate = yypgoto_[yyn - yyntokens_] + yystate_stack_[0];
471 if (0 <= yystate && yystate <= yylast_
472 && yycheck_[yystate] == yystate_stack_[0])
473 yystate = yytable_[yystate];
474 else
475 yystate = yydefgoto_[yyn - yyntokens_];
476 goto yynewstate;
477
478 /*------------------------------------.
479 | yyerrlab -- here on detecting error |
480 `------------------------------------*/
481 yyerrlab:
482 /* If not already recovering from an error, report this error. */
483 if (!yyerrstatus_)
484 {
485 ++yynerrs_;
486 error (yylloc, yysyntax_error_ (yystate, yytoken));
487 }
488
489 yyerror_range[0] = yylloc;
490 if (yyerrstatus_ == 3)
491 {
492 /* If just tried and failed to reuse look-ahead token after an
493 error, discard it. */
494
495 if (yychar <= yyeof_)
496 {
497 /* Return failure if at end of input. */
498 if (yychar == yyeof_)
499 YYABORT;
500 }
501 else
502 {
503 yydestruct_ ("Error: discarding", yytoken, &yylval, &yylloc);
504 yychar = yyempty_;
505 }
506 }
507
508 /* Else will try to reuse look-ahead token after shifting the error
509 token. */
510 goto yyerrlab1;
511
512
513 /*---------------------------------------------------.
514 | yyerrorlab -- error raised explicitly by YYERROR. |
515 `---------------------------------------------------*/
516 yyerrorlab:
517
518 /* Pacify compilers like GCC when the user code never invokes
519 YYERROR and the label yyerrorlab therefore never appears in user
520 code. */
521 if (false)
522 goto yyerrorlab;
523
524 yyerror_range[0] = yylocation_stack_[yylen - 1];
525 /* Do not reclaim the symbols of the rule which action triggered
526 this YYERROR. */
527 yypop_ (yylen);
528 yylen = 0;
529 yystate = yystate_stack_[0];
530 goto yyerrlab1;
531
532 /*-------------------------------------------------------------.
533 | yyerrlab1 -- common code for both syntax error and YYERROR. |
534 `-------------------------------------------------------------*/
535 yyerrlab1:
536 yyerrstatus_ = 3; /* Each real token shifted decrements this. */
537
538 for (;;)
539 {
540 yyn = yypact_[yystate];
541 if (yyn != yypact_ninf_)
542 {
543 yyn += yyterror_;
544 if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
545 {
546 yyn = yytable_[yyn];
547 if (0 < yyn)
548 break;
549 }
550 }
551
552 /* Pop the current state because it cannot handle the error token. */
553 if (yystate_stack_.height () == 1)
554 YYABORT;
555
556 yyerror_range[0] = yylocation_stack_[0];
557 yydestruct_ ("Error: popping",
558 yystos_[yystate],
559 &yysemantic_stack_[0], &yylocation_stack_[0]);
560 yypop_ ();
561 yystate = yystate_stack_[0];
562 YY_STACK_PRINT ();
563 }
564
565 if (yyn == yyfinal_)
566 goto yyacceptlab;
567
568 yyerror_range[1] = yylloc;
569 // Using YYLLOC is tempting, but would change the location of
570 // the look-ahead. YYLOC is available though.
571 YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);
572 yysemantic_stack_.push (yylval);
573 yylocation_stack_.push (yyloc);
574
575 /* Shift the error token. */
576 YY_SYMBOL_PRINT ("Shifting", yystos_[yyn],
577 &yysemantic_stack_[0], &yylocation_stack_[0]);
578
579 yystate = yyn;
580 goto yynewstate;
581
582 /* Accept. */
583 yyacceptlab:
584 yyresult = 0;
585 goto yyreturn;
586
587 /* Abort. */
588 yyabortlab:
589 yyresult = 1;
590 goto yyreturn;
591
592 yyreturn:
593 if (yychar != yyeof_ && yychar != yyempty_)
594 yydestruct_ ("Cleanup: discarding lookahead", yytoken, &yylval, &yylloc);
595
596 /* Do not reclaim the symbols of the rule which action triggered
597 this YYABORT or YYACCEPT. */
598 yypop_ (yylen);
599 while (yystate_stack_.height () != 1)
600 {
601 yydestruct_ ("Cleanup: popping",
602 yystos_[yystate_stack_[0]],
603 &yysemantic_stack_[0],
604 &yylocation_stack_[0]);
605 yypop_ ();
606 }
607
608 return yyresult;
609 }
610
611 // Generate an error message.
612 std::string
613 calc_parser::yysyntax_error_ (int yystate, int tok)
614 {
615 std::string res;
616 YYUSE (yystate);
617 #if YYERROR_VERBOSE
618 int yyn = yypact_[yystate];
619 if (yypact_ninf_ < yyn && yyn <= yylast_)
620 {
621 /* Start YYX at -YYN if negative to avoid negative indexes in
622 YYCHECK. */
623 int yyxbegin = yyn < 0 ? -yyn : 0;
624
625 /* Stay within bounds of both yycheck and yytname. */
626 int yychecklim = yylast_ - yyn + 1;
627 int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
628 int count = 0;
629 for (int x = yyxbegin; x < yyxend; ++x)
630 if (yycheck_[x + yyn] == x && x != yyterror_)
631 ++count;
632
633 // FIXME: This method of building the message is not compatible
634 // with internationalization. It should work like yacc.c does it.
635 // That is, first build a string that looks like this:
636 // "syntax error, unexpected %s or %s or %s"
637 // Then, invoke YY_ on this string.
638 // Finally, use the string as a format to output
639 // yytname_[tok], etc.
640 // Until this gets fixed, this message appears in English only.
641 res = "syntax error, unexpected ";
642 res += yytnamerr_ (yytname_[tok]);
643 if (count < 5)
644 {
645 count = 0;
646 for (int x = yyxbegin; x < yyxend; ++x)
647 if (yycheck_[x + yyn] == x && x != yyterror_)
648 {
649 res += (!count++) ? ", expecting " : " or ";
650 res += yytnamerr_ (yytname_[x]);
651 }
652 }
653 }
654 else
655 #endif
656 res = YY_("syntax error");
657 return res;
658 }
659
660
661 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
662 STATE-NUM. */
663 const signed char calc_parser::yypact_ninf_ = -9;
664 const signed char
665 calc_parser::yypact_[] =
666 {
667 3, -1, 2, 13, 32, -9, 2, -9, -9, 2,
668 2, 14, -9, -9, -9, 21, -9, 10, 2, 2,
669 2, 2, -9, -9, -9, -8, -8, -9, -9
670 };
671
672 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
673 doesn't specify something else to do. Zero means the default is an
674 error. */
675 const unsigned char
676 calc_parser::yydefact_[] =
677 {
678 0, 0, 0, 0, 0, 2, 0, 14, 13, 0,
679 0, 0, 6, 1, 3, 0, 11, 0, 0, 0,
680 0, 0, 5, 4, 12, 8, 7, 9, 10
681 };
682
683 /* YYPGOTO[NTERM-NUM]. */
684 const signed char
685 calc_parser::yypgoto_[] =
686 {
687 -9, -9, 29, -6
688 };
689
690 /* YYDEFGOTO[NTERM-NUM]. */
691 const signed char
692 calc_parser::yydefgoto_[] =
693 {
694 -1, 4, 5, 11
695 };
696
697 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
698 positive, shift that token. If negative, reduce the rule which
699 number is the opposite. If zero, do what YYDEFACT says. */
700 const signed char calc_parser::yytable_ninf_ = -1;
701 const unsigned char
702 calc_parser::yytable_[] =
703 {
704 15, 20, 21, 16, 17, 7, 8, 1, 2, 3,
705 9, 6, 25, 26, 27, 28, 10, 18, 19, 20,
706 21, 18, 19, 20, 21, 24, 12, 22, 18, 19,
707 20, 21, 13, 14, 23, 0, 1, 2, 3
708 };
709
710 /* YYCHECK. */
711 const signed char
712 calc_parser::yycheck_[] =
713 {
714 6, 9, 10, 9, 10, 3, 4, 4, 5, 6,
715 8, 12, 18, 19, 20, 21, 14, 7, 8, 9,
716 10, 7, 8, 9, 10, 15, 13, 13, 7, 8,
717 9, 10, 0, 4, 13, -1, 4, 5, 6
718 };
719
720 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
721 symbol of state STATE-NUM. */
722 const unsigned char
723 calc_parser::yystos_[] =
724 {
725 0, 4, 5, 6, 17, 18, 12, 3, 4, 8,
726 14, 19, 13, 0, 18, 19, 19, 19, 7, 8,
727 9, 10, 13, 13, 15, 19, 19, 19, 19
728 };
729
730 #if YYDEBUG
731 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
732 to YYLEX-NUM. */
733 const unsigned short int
734 calc_parser::yytoken_number_[] =
735 {
736 0, 256, 257, 258, 259, 260, 261, 43, 45, 42,
737 47, 262, 61, 10, 40, 41
738 };
739 #endif
740
741 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
742 const unsigned char
743 calc_parser::yyr1_[] =
744 {
745 0, 16, 17, 17, 18, 18, 18, 19, 19, 19,
746 19, 19, 19, 19, 19
747 };
748
749 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
750 const unsigned char
751 calc_parser::yyr2_[] =
752 {
753 0, 2, 1, 2, 4, 3, 2, 3, 3, 3,
754 3, 2, 3, 1, 1
755 };
756
757 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
758 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
759 First, the terminals, then, starting at \a yyntokens_, nonterminals. */
760 const char*
761 const calc_parser::yytname_[] =
762 {
763 "\"end of file\"", "error", "$undefined", "\"ival\"", "\"identifier\"",
764 "\"print\"", "\"list\"", "'+'", "'-'", "'*'", "'/'", "NEG", "'='",
765 "'\\n'", "'('", "')'", "$accept", "unit", "state", "expr", 0
766 };
767 #endif
768
769 #if YYDEBUG
770 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
771 const calc_parser::rhs_number_type
772 calc_parser::yyrhs_[] =
773 {
774 17, 0, -1, 18, -1, 17, 18, -1, 4, 12,
775 19, 13, -1, 5, 19, 13, -1, 6, 13, -1,
776 19, 8, 19, -1, 19, 7, 19, -1, 19, 9,
777 19, -1, 19, 10, 19, -1, 8, 19, -1, 14,
778 19, 15, -1, 4, -1, 3, -1
779 };
780
781 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
782 YYRHS. */
783 const unsigned char
784 calc_parser::yyprhs_[] =
785 {
786 0, 0, 3, 5, 8, 13, 17, 20, 24, 28,
787 32, 36, 39, 43, 45
788 };
789
790 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
791 const unsigned char
792 calc_parser::yyrline_[] =
793 {
794 0, 48, 48, 49, 52, 53, 54, 57, 58, 59,
795 60, 61, 62, 63, 64
796 };
797
798 // Print the state stack on the debug stream.
799 void
800 calc_parser::yystack_print_ ()
801 {
802 *yycdebug_ << "Stack now";
803 for (state_stack_type::const_iterator i = yystate_stack_.begin ();
804 i != yystate_stack_.end (); ++i)
805 *yycdebug_ << ' ' << *i;
806 *yycdebug_ << std::endl;
807 }
808
809 // Report on the debug stream that the rule \a yyrule is going to be reduced.
810 void
811 calc_parser::yy_reduce_print_ (int yyrule)
812 {
813 unsigned int yylno = yyrline_[yyrule];
814 int yynrhs = yyr2_[yyrule];
815 /* Print the symbols being reduced, and their result. */
816 *yycdebug_ << "Reducing stack by rule " << yyrule - 1
817 << " (line " << yylno << "), ";
818 /* The symbols being reduced. */
819 for (int yyi = 0; yyi < yynrhs; yyi++)
820 YY_SYMBOL_PRINT (" $" << yyi + 1 << " =",
821 yyrhs_[yyprhs_[yyrule] + yyi],
822 &(yysemantic_stack_[(yynrhs) - (yyi + 1)]),
823 &(yylocation_stack_[(yynrhs) - (yyi + 1)]));
824 }
825 #endif // YYDEBUG
826
827 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
828 calc_parser::token_number_type
829 calc_parser::yytranslate_ (int t)
830 {
831 static
832 const token_number_type
833 translate_table[] =
834 {
835 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
836 13, 2, 2, 2, 2, 2, 2, 2, 2, 2,
837 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
838 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
839 14, 15, 9, 7, 2, 8, 2, 10, 2, 2,
840 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
841 2, 12, 2, 2, 2, 2, 2, 2, 2, 2,
842 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
843 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
844 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
845 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
846 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
847 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
848 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
849 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
850 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
851 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
852 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
853 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
854 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
855 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
856 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
857 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
858 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
859 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
860 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
861 5, 6, 11
862 };
863 if ((unsigned int) t <= yyuser_token_number_max_)
864 return translate_table[t];
865 else
866 return yyundef_token_;
867 }
868
869 const int calc_parser::yyeof_ = 0;
870 const int calc_parser::yylast_ = 38;
871 const int calc_parser::yynnts_ = 4;
872 const int calc_parser::yyempty_ = -2;
873 const int calc_parser::yyfinal_ = 13;
874 const int calc_parser::yyterror_ = 1;
875 const int calc_parser::yyerrcode_ = 256;
876 const int calc_parser::yyntokens_ = 16;
877
878 const unsigned int calc_parser::yyuser_token_number_max_ = 262;
879 const calc_parser::token_number_type calc_parser::yyundef_token_ = 2;
880
881 } // namespace yy
882
883 #line 67 "calc-parser.yy"
884
885 void yy::calc_parser::error(const yy::calc_parser::location_type&, const std::string& m)
886 {
887 driver.error(m);
888 }
889