Bridge++  Version 1.6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
evalexpr_parser.cpp
Go to the documentation of this file.
1 /* A Bison parser, made by GNU Bison 2.7. */
2 
3 /* Skeleton implementation for Bison LALR(1) parsers in C++
4 
5  Copyright (C) 2002-2012 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 3 of the License, or
10  (at your option) 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, see <http://www.gnu.org/licenses/>. */
19 
20 /* As a special exception, you may create a larger work that contains
21  part or all of the Bison parser skeleton and distribute that work
22  under terms of your choice, so long as that work isn't itself a
23  parser generator using the skeleton or a modified version thereof
24  as a parser skeleton. Alternatively, if you modify or redistribute
25  the parser skeleton itself, you may (at your option) remove this
26  special exception, which will cause the skeleton and the resulting
27  Bison output files to be licensed under the GNU General Public
28  License without this special exception.
29 
30  This special exception was added by the Free Software Foundation in
31  version 2.2 of Bison. */
32 
38 /* First part of user declarations. */
39 
40 /* Line 279 of lalr1.cc */
41 #line 38 "evalexpr_parser.cpp"
42 
43 
44 #include "evalexpr_parser.h"
45 
46 /* User implementation prologue. */
47 
48 /* Line 285 of lalr1.cc */
49 #line 46 "evalexpr_parser.cpp"
50 /* Unqualified %code blocks. */
51 /* Line 286 of lalr1.cc */
52 #line 26 "evalexpr_parser.yy"
53 
54 #include "evalexpr.h"
55 
56 
57 /* Line 286 of lalr1.cc */
58 #line 55 "evalexpr_parser.cpp"
59 
60 
61 # ifndef YY_NULL
62 # if defined __cplusplus && 201103L <= __cplusplus
63 # define YY_NULL nullptr
64 # else
65 # define YY_NULL 0
66 # endif
67 # endif
68 
69 #ifndef YY_
70 # if defined YYENABLE_NLS && YYENABLE_NLS
71 # if ENABLE_NLS
72 # include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
73 # define YY_(msgid) dgettext("bison-runtime", msgid)
74 # endif
75 # endif
76 # ifndef YY_
77 # define YY_(msgid) msgid
78 # endif
79 #endif
80 
81 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
82 
83 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
84  If N is 0, then set CURRENT to the empty location which ends
85  the previous symbol: RHS[0] (always defined). */
86 
87 # ifndef YYLLOC_DEFAULT
88 # define YYLLOC_DEFAULT(Current, Rhs, N) \
89  do { \
90  if (N) \
91  { \
92  (Current).begin = YYRHSLOC(Rhs, 1).begin; \
93  (Current).end = YYRHSLOC(Rhs, N).end; \
94  } \
95  else \
96  { \
97  (Current).begin = (Current).end = YYRHSLOC(Rhs, 0).end; \
98  } \
99  } \
100  while (/*CONSTCOND*/ false)
101 # endif
102 
103 
104 /* Suppress unused-variable warnings by "using" E. */
105 #define YYUSE(e) ((void)(e))
106 
107 /* Enable debugging if requested. */
108 #if YYDEBUG
109 
110 /* A pseudo ostream that takes yydebug_ into account. */
111 # define YYCDEBUG if (yydebug_) (*yycdebug_)
112 
113 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
114  do { \
115  if (yydebug_) \
116  { \
117  *yycdebug_ << Title << ' '; \
118  yy_symbol_print_((Type), (Value), (Location)); \
119  *yycdebug_ << std::endl; \
120  } \
121  } \
122  while (false)
123 
124 # define YY_REDUCE_PRINT(Rule) \
125  do { \
126  if (yydebug_) \
127  yy_reduce_print_(Rule); \
128  } \
129  while (false)
130 
131 # define YY_STACK_PRINT() \
132  do { \
133  if (yydebug_) \
134  yystack_print_(); \
135  } \
136  while (false)
137 
138 #else /* !YYDEBUG */
139 
140 # define YYCDEBUG if (false) std::cerr
141 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) YYUSE(Type)
142 # define YY_REDUCE_PRINT(Rule) static_cast<void>(0)
143 # define YY_STACK_PRINT() static_cast<void>(0)
144 #endif /* !YYDEBUG */
145 
146 #define yyerrok (yyerrstatus_ = 0)
147 #define yyclearin (yychar = yyempty_)
148 
149 #define YYACCEPT goto yyacceptlab
150 #define YYABORT goto yyabortlab
151 #define YYERROR goto yyerrorlab
152 #define YYRECOVERING() (!!yyerrstatus_)
153 
154 /* Line 353 of lalr1.cc */
155 #line 4 "evalexpr_parser.yy"
156 namespace yy {
157 /* Line 353 of lalr1.cc */
158 #line 151 "evalexpr_parser.cpp"
159 
160  /* Return YYSTR after stripping away unnecessary quotes and
161  backslashes, so that it's suitable for yyerror. The heuristic is
162  that double-quoting is unnecessary unless the string contains an
163  apostrophe, a comma, or backslash (other than backslash-backslash).
164  YYSTR is taken from yytname. */
165  std::string
166  parser::yytnamerr_(const char *yystr)
167  {
168  if (*yystr == '"')
169  {
170  std::string yyr = "";
171  char const *yyp = yystr;
172 
173  for ( ; ;) {
174  switch (*++yyp)
175  {
176  case '\'':
177  case ',':
178  goto do_not_strip_quotes;
179 
180  case '\\':
181  if (*++yyp != '\\')
182  goto do_not_strip_quotes;
183 
184  /* Fall through. */
185  default:
186  yyr += *yyp;
187  break;
188 
189  case '"':
190  return yyr;
191  }
192  }
193 do_not_strip_quotes:;
194  }
195 
196  return yystr;
197  }
198 
199 
201  parser::parser(EvalExpr& driver_yyarg)
202  :
203 #if YYDEBUG
204  yydebug_(false),
205  yycdebug_(&std::cerr),
206 #endif
207  driver(driver_yyarg)
208  {
209  }
210 
211 
213  {
214  }
215 
216 
217 #if YYDEBUG
218  /*--------------------------------.
219  | Print this symbol on YYOUTPUT. |
220  `--------------------------------*/
221  inline void
223  const semantic_type *yyvaluep, const location_type *yylocationp)
224  {
225  YYUSE(yylocationp);
226  YYUSE(yyvaluep);
227  std::ostream& yyo = debug_stream();
228  std::ostream& yyoutput = yyo;
229  YYUSE(yyoutput);
230  switch (yytype)
231  {
232  case 4: /* IDENTIFIER */
233 /* Line 423 of lalr1.cc */
234 #line 40 "evalexpr_parser.yy"
235  yyoutput << ((*yyvaluep).sym);
236 /* Line 423 of lalr1.cc */
237 #line 227 "evalexpr_parser.cpp"
238  break;
239 
240  case 5: /* NUMBER */
241 /* Line 423 of lalr1.cc */
242 #line 41 "evalexpr_parser.yy"
243  yyoutput << ((*yyvaluep).val);
244 /* Line 423 of lalr1.cc */
245 #line 234 "evalexpr_parser.cpp"
246  break;
247 
248  case 17: /* expr */
249 /* Line 423 of lalr1.cc */
250 #line 41 "evalexpr_parser.yy"
251  yyoutput << ((*yyvaluep).val);
252 /* Line 423 of lalr1.cc */
253 #line 241 "evalexpr_parser.cpp"
254  break;
255 
256  default:
257  break;
258  }
259  }
260 
261 
262  void
264  const semantic_type *yyvaluep, const location_type *yylocationp)
265  {
266  *yycdebug_ << (yytype < yyntokens_ ? "token" : "nterm")
267  << ' ' << yytname_[yytype] << " ("
268  << *yylocationp << ": ";
269  yy_symbol_value_print_(yytype, yyvaluep, yylocationp);
270  *yycdebug_ << ')';
271  }
272 #endif
273 
274  void
275  parser::yydestruct_(const char *yymsg,
276  int yytype, semantic_type *yyvaluep, location_type *yylocationp)
277  {
278  YYUSE(yylocationp);
279  YYUSE(yymsg);
280  YYUSE(yyvaluep);
281 
282  if (yymsg)
283  YY_SYMBOL_PRINT(yymsg, yytype, yyvaluep, yylocationp);
284 
285  switch (yytype)
286  {
287  case 4: /* IDENTIFIER */
288 /* Line 455 of lalr1.cc */
289 #line 43 "evalexpr_parser.yy"
290  free(((*yyvaluep).sym));
291 /* Line 455 of lalr1.cc */
292 #line 279 "evalexpr_parser.cpp"
293  break;
294 
295  default:
296  break;
297  }
298  }
299 
300 
301  void
302  parser::yypop_(unsigned int n)
303  {
304  yystate_stack_.pop(n);
307  }
308 
309 
310 #if YYDEBUG
311  std::ostream&
313  {
314  return *yycdebug_;
315  }
316 
317 
318  void
319  parser::set_debug_stream(std::ostream& o)
320  {
321  yycdebug_ = &o;
322  }
323 
324 
327  {
328  return yydebug_;
329  }
330 
331 
332  void
334  {
335  yydebug_ = l;
336  }
337 #endif
338 
339  inline bool
341  {
342  return yyvalue == yypact_ninf_;
343  }
344 
345 
346  inline bool
348  {
349  return yyvalue == yytable_ninf_;
350  }
351 
352 
353  int
355  {
357  int yychar = yyempty_;
358  int yytoken = 0;
359 
360  // State.
361  int yyn;
362  int yylen = 0;
363  int yystate = 0;
364 
365  // Error handling.
366  int yynerrs_ = 0;
367  int yyerrstatus_ = 0;
368 
370  static semantic_type yyval_default;
371  semantic_type yylval = yyval_default;
373  location_type yylloc;
375  location_type yyerror_range[3];
376 
378  semantic_type yyval;
380  location_type yyloc;
381 
382  int yyresult;
383 
384  // FIXME: This shoud be completely indented. It is not yet to
385  // avoid gratuitous conflicts when merging into the master branch.
386 #ifndef NOEXCEPTION
387  try
388 #endif
389  {
390  YYCDEBUG << "Starting parse" << std::endl;
391 
392 
393  /* Initialize the stacks. The initial state will be pushed in
394  yynewstate, since the latter expects the semantical and the
395  location values to have been already stored, initialize these
396  stacks with a primary value. */
400  yysemantic_stack_.push(yylval);
401  yylocation_stack_.push(yylloc);
402 
403  /* New state. */
404 yynewstate:
405  yystate_stack_.push(yystate);
406  YYCDEBUG << "Entering state " << yystate << std::endl;
407 
408  /* Accept? */
409  if (yystate == yyfinal_)
410  goto yyacceptlab;
411 
412  goto yybackup;
413 
414  /* Backup. */
415 yybackup:
416 
417  /* Try to take a decision without lookahead. */
418  yyn = yypact_[yystate];
419  if (yy_pact_value_is_default_(yyn))
420  goto yydefault;
421 
422  /* Read a lookahead token. */
423  if (yychar == yyempty_)
424  {
425  YYCDEBUG << "Reading a token: ";
426  yychar = yylex(&yylval, driver);
427  }
428 
429  /* Convert token to internal form. */
430  if (yychar <= yyeof_)
431  {
432  yychar = yytoken = yyeof_;
433  YYCDEBUG << "Now at end of input." << std::endl;
434  } else
435  {
436  yytoken = yytranslate_(yychar);
437  YY_SYMBOL_PRINT("Next token is", yytoken, &yylval, &yylloc);
438  }
439 
440  /* If the proper action on seeing token YYTOKEN is to reduce or to
441  detect an error, take that action. */
442  yyn += yytoken;
443  if ((yyn < 0) || (yylast_ < yyn) || (yycheck_[yyn] != yytoken))
444  goto yydefault;
445 
446  /* Reduce or error. */
447  yyn = yytable_[yyn];
448  if (yyn <= 0)
449  {
450  if (yy_table_value_is_error_(yyn))
451  goto yyerrlab;
452  yyn = -yyn;
453  goto yyreduce;
454  }
455 
456  /* Shift the lookahead token. */
457  YY_SYMBOL_PRINT("Shifting", yytoken, &yylval, &yylloc);
458 
459  /* Discard the token being shifted. */
460  yychar = yyempty_;
461 
462  yysemantic_stack_.push(yylval);
463  yylocation_stack_.push(yylloc);
464 
465  /* Count tokens shifted since error; after three, turn off error
466  status. */
467  if (yyerrstatus_)
468  --yyerrstatus_;
469 
470  yystate = yyn;
471  goto yynewstate;
472 
473  /*-----------------------------------------------------------.
474  | yydefault -- do the default action for the current state. |
475  `-----------------------------------------------------------*/
476 yydefault:
477  yyn = yydefact_[yystate];
478  if (yyn == 0)
479  goto yyerrlab;
480  goto yyreduce;
481 
482  /*-----------------------------.
483  | yyreduce -- Do a reduction. |
484  `-----------------------------*/
485 yyreduce:
486  yylen = yyr2_[yyn];
487 
488  /* If YYLEN is nonzero, implement the default value of the action:
489  `$$ = $1'. Otherwise, use the top of the stack.
490 
491  Otherwise, the following line sets YYVAL to garbage.
492  This behavior is undocumented and Bison
493  users should not rely upon it. */
494  if (yylen)
495  yyval = yysemantic_stack_[yylen - 1];
496  else
497  yyval = yysemantic_stack_[0];
498 
499  // Compute the default @$.
500  {
502  YYLLOC_DEFAULT(yyloc, slice, yylen);
503  }
504 
505  // Perform the reduction.
506  YY_REDUCE_PRINT(yyn);
507  switch (yyn)
508  {
509  case 3:
510 /* Line 670 of lalr1.cc */
511 #line 49 "evalexpr_parser.yy"
512  driver.set_result((yysemantic_stack_[(1) - (1)].val));
513  break;
514 
515  case 4:
516 /* Line 670 of lalr1.cc */
517 #line 51 "evalexpr_parser.yy"
518  (yyval.val) = (yysemantic_stack_[(1) - (1)].val);
519  break;
520 
521  case 5:
522 /* Line 670 of lalr1.cc */
523 #line 52 "evalexpr_parser.yy"
524  (yyval.val) = driver.get_symbol_value((yysemantic_stack_[(1) - (1)].sym));
525  free((yysemantic_stack_[(1) - (1)].sym));
526  break;
527 
528  case 6:
529 /* Line 670 of lalr1.cc */
530 #line 53 "evalexpr_parser.yy"
531  (yyval.val) = (driver.get_symbol_function((yysemantic_stack_[(4) - (1)].sym)))((yysemantic_stack_[(4) - (3)].val));
532  free((yysemantic_stack_[(4) - (1)].sym));
533  break;
534 
535  case 7:
536 /* Line 670 of lalr1.cc */
537 #line 54 "evalexpr_parser.yy"
538  (yyval.val) = (yysemantic_stack_[(3) - (1)].val) + (yysemantic_stack_[(3) - (3)].val);
539  break;
540 
541  case 8:
542 /* Line 670 of lalr1.cc */
543 #line 55 "evalexpr_parser.yy"
544  (yyval.val) = (yysemantic_stack_[(3) - (1)].val) - (yysemantic_stack_[(3) - (3)].val);
545  break;
546 
547  case 9:
548 /* Line 670 of lalr1.cc */
549 #line 56 "evalexpr_parser.yy"
550  (yyval.val) = (yysemantic_stack_[(3) - (1)].val) * (yysemantic_stack_[(3) - (3)].val);
551  break;
552 
553  case 10:
554 /* Line 670 of lalr1.cc */
555 #line 57 "evalexpr_parser.yy"
556  (yyval.val) = (yysemantic_stack_[(3) - (1)].val) / (yysemantic_stack_[(3) - (3)].val);
557  break;
558 
559  case 11:
560 /* Line 670 of lalr1.cc */
561 #line 58 "evalexpr_parser.yy"
562  (yyval.val) = (yysemantic_stack_[(2) - (2)].val);
563  break;
564 
565  case 12:
566 /* Line 670 of lalr1.cc */
567 #line 59 "evalexpr_parser.yy"
568  (yyval.val) = -(yysemantic_stack_[(2) - (2)].val);
569  break;
570 
571  case 13:
572 /* Line 670 of lalr1.cc */
573 #line 60 "evalexpr_parser.yy"
574  (yyval.val) = pow((yysemantic_stack_[(3) - (1)].val), (yysemantic_stack_[(3) - (3)].val));
575  break;
576 
577  case 14:
578 /* Line 670 of lalr1.cc */
579 #line 61 "evalexpr_parser.yy"
580  (yyval.val) = (yysemantic_stack_[(3) - (2)].val);
581  break;
582 
583 
584 /* Line 670 of lalr1.cc */
585 #line 562 "evalexpr_parser.cpp"
586  default:
587  break;
588  }
589 
590  /* User semantic actions sometimes alter yychar, and that requires
591  that yytoken be updated with the new translation. We take the
592  approach of translating immediately before every use of yytoken.
593  One alternative is translating here after every semantic action,
594  but that translation would be missed if the semantic action
595  invokes YYABORT, YYACCEPT, or YYERROR immediately after altering
596  yychar. In the case of YYABORT or YYACCEPT, an incorrect
597  destructor might then be invoked immediately. In the case of
598  YYERROR, subsequent parser actions might lead to an incorrect
599  destructor call or verbose syntax error message before the
600  lookahead is translated. */
601  YY_SYMBOL_PRINT("-> $$ =", yyr1_[yyn], &yyval, &yyloc);
602 
603  yypop_(yylen);
604  yylen = 0;
605  YY_STACK_PRINT();
606 
607  yysemantic_stack_.push(yyval);
608  yylocation_stack_.push(yyloc);
609 
610  /* Shift the result of the reduction. */
611  yyn = yyr1_[yyn];
612  yystate = yypgoto_[yyn - yyntokens_] + yystate_stack_[0];
613  if ((0 <= yystate) && (yystate <= yylast_) &&
614  (yycheck_[yystate] == yystate_stack_[0]))
615  yystate = yytable_[yystate];
616  else
617  yystate = yydefgoto_[yyn - yyntokens_];
618  goto yynewstate;
619 
620  /*------------------------------------.
621  | yyerrlab -- here on detecting error |
622  `------------------------------------*/
623 yyerrlab:
624 
625  /* Make sure we have latest lookahead translation. See comments at
626  user semantic actions for why this is necessary. */
627  yytoken = yytranslate_(yychar);
628 
629  /* If not already recovering from an error, report this error. */
630  if (!yyerrstatus_)
631  {
632  ++yynerrs_;
633  if (yychar == yyempty_)
634  yytoken = yyempty_;
635  error(yylloc, yysyntax_error_(yystate, yytoken));
636  }
637 
638  yyerror_range[1] = yylloc;
639  if (yyerrstatus_ == 3)
640  {
641  /* If just tried and failed to reuse lookahead token after an
642  error, discard it. */
643  if (yychar <= yyeof_)
644  {
645  /* Return failure if at end of input. */
646  if (yychar == yyeof_)
647  YYABORT;
648  } else
649  {
650  yydestruct_("Error: discarding", yytoken, &yylval, &yylloc);
651  yychar = yyempty_;
652  }
653  }
654 
655  /* Else will try to reuse lookahead token after shifting the error
656  token. */
657  goto yyerrlab1;
658 
659 
660  /*---------------------------------------------------.
661  | yyerrorlab -- error raised explicitly by YYERROR. |
662  `---------------------------------------------------*/
663 yyerrorlab:
664 
665  /* Pacify compilers like GCC when the user code never invokes
666  YYERROR and the label yyerrorlab therefore never appears in user
667  code. */
668  if (false)
669  goto yyerrorlab;
670 
671  yyerror_range[1] = yylocation_stack_[yylen - 1];
672 
673  /* Do not reclaim the symbols of the rule which action triggered
674  this YYERROR. */
675  yypop_(yylen);
676  yylen = 0;
677  yystate = yystate_stack_[0];
678  goto yyerrlab1;
679 
680  /*-------------------------------------------------------------.
681  | yyerrlab1 -- common code for both syntax error and YYERROR. |
682  `-------------------------------------------------------------*/
683 yyerrlab1:
684  yyerrstatus_ = 3; /* Each real token shifted decrements this. */
685 
686  for ( ; ;) {
687  yyn = yypact_[yystate];
688  if (!yy_pact_value_is_default_(yyn))
689  {
690  yyn += yyterror_;
691  if ((0 <= yyn) && (yyn <= yylast_) && (yycheck_[yyn] == yyterror_))
692  {
693  yyn = yytable_[yyn];
694  if (0 < yyn)
695  break;
696  }
697  }
698 
699  /* Pop the current state because it cannot handle the error token. */
700  if (yystate_stack_.height() == 1)
701  YYABORT;
702 
703  yyerror_range[1] = yylocation_stack_[0];
704  yydestruct_("Error: popping",
705  yystos_[yystate],
707  yypop_();
708  yystate = yystate_stack_[0];
709  YY_STACK_PRINT();
710  }
711 
712  yyerror_range[2] = yylloc;
713  // Using YYLLOC is tempting, but would change the location of
714  // the lookahead. YYLOC is available though.
715  YYLLOC_DEFAULT(yyloc, yyerror_range, 2);
716  yysemantic_stack_.push(yylval);
717  yylocation_stack_.push(yyloc);
718 
719  /* Shift the error token. */
720  YY_SYMBOL_PRINT("Shifting", yystos_[yyn],
722 
723  yystate = yyn;
724  goto yynewstate;
725 
726  /* Accept. */
727 yyacceptlab:
728  yyresult = 0;
729  goto yyreturn;
730 
731  /* Abort. */
732 yyabortlab:
733  yyresult = 1;
734  goto yyreturn;
735 
736 yyreturn:
737  if (yychar != yyempty_)
738  {
739  /* Make sure we have latest lookahead translation. See comments
740  at user semantic actions for why this is necessary. */
741  yytoken = yytranslate_(yychar);
742  yydestruct_("Cleanup: discarding lookahead", yytoken, &yylval,
743  &yylloc);
744  }
745 
746  /* Do not reclaim the symbols of the rule which action triggered
747  this YYABORT or YYACCEPT. */
748  yypop_(yylen);
749  while (1 < yystate_stack_.height())
750  {
751  yydestruct_("Cleanup: popping",
752  yystos_[yystate_stack_[0]],
753  &yysemantic_stack_[0],
754  &yylocation_stack_[0]);
755  yypop_();
756  }
757 
758  return yyresult;
759  }
760 #ifndef NOEXCEPTION
761  catch (...)
762  {
763  YYCDEBUG << "Exception caught: cleaning lookahead and stack"
764  << std::endl;
765  // Do not try to display the values of the reclaimed symbols,
766  // as their printer might throw an exception.
767  if (yychar != yyempty_)
768  {
769  /* Make sure we have latest lookahead translation. See
770  comments at user semantic actions for why this is
771  necessary. */
772  yytoken = yytranslate_(yychar);
773  yydestruct_(YY_NULL, yytoken, &yylval, &yylloc);
774  }
775 
776  while (1 < yystate_stack_.height())
777  {
780  &yysemantic_stack_[0],
781  &yylocation_stack_[0]);
782  yypop_();
783  }
784  throw;
785  }
786 #endif
787  }
788 
789 
790  // Generate an error message.
791  std::string
792  parser::yysyntax_error_(int yystate, int yytoken)
793  {
794  std::string yyres;
795  // Number of reported tokens (one for the "unexpected", one per
796  // "expected").
797  size_t yycount = 0;
798 
799  // Its maximum.
800  enum
801  {
802  YYERROR_VERBOSE_ARGS_MAXIMUM = 5
803  };
804  // Arguments of yyformat.
805  char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
806 
807  /* There are many possibilities here to consider:
808  - If this state is a consistent state with a default action, then
809  the only way this function was invoked is if the default action
810  is an error action. In that case, don't check for expected
811  tokens because there are none.
812  - The only way there can be no lookahead present (in yytoken) is
813  if this state is a consistent state with a default action.
814  Thus, detecting the absence of a lookahead is sufficient to
815  determine that there is no unexpected or expected token to
816  report. In that case, just report a simple "syntax error".
817  - Don't assume there isn't a lookahead just because this state is
818  a consistent state with a default action. There might have
819  been a previous inconsistent state, consistent state with a
820  non-default action, or user semantic action that manipulated
821  yychar.
822  - Of course, the expected token list depends on states to have
823  correct lookahead information, and it depends on the parser not
824  to perform extra reductions after fetching a lookahead from the
825  scanner and before detecting a syntax error. Thus, state
826  merging (from LALR or IELR) and default reductions corrupt the
827  expected token list. However, the list is correct for
828  canonical LR with one exception: it will still contain any
829  token that will not be accepted due to an error action in a
830  later state.
831  */
832  if (yytoken != yyempty_)
833  {
834  yyarg[yycount++] = yytname_[yytoken];
835  int yyn = yypact_[yystate];
836  if (!yy_pact_value_is_default_(yyn))
837  {
838  /* Start YYX at -YYN if negative to avoid negative indexes in
839  YYCHECK. In other words, skip the first -YYN actions for
840  this state because they are default actions. */
841  int yyxbegin = yyn < 0 ? -yyn : 0;
842  /* Stay within bounds of both yycheck and yytname. */
843  int yychecklim = yylast_ - yyn + 1;
844  int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
845  for (int yyx = yyxbegin; yyx < yyxend; ++yyx) {
846  if ((yycheck_[yyx + yyn] == yyx) && (yyx != yyterror_) &&
847  !yy_table_value_is_error_(yytable_[yyx + yyn]))
848  {
849  if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
850  {
851  yycount = 1;
852  break;
853  } else
854  yyarg[yycount++] = yytname_[yyx];
855  }
856  }
857  }
858  }
859 
860  char const *yyformat = YY_NULL;
861  switch (yycount)
862  {
863 #define YYCASE_(N, S) \
864 case N: \
865  yyformat = S; \
866  break
867  YYCASE_(0, YY_("syntax error"));
868  YYCASE_(1, YY_("syntax error, unexpected %s"));
869  YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
870  YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
871  YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
872  YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
873 #undef YYCASE_
874  }
875 
876  // Argument number.
877  size_t yyi = 0;
878  for (char const *yyp = yyformat; *yyp; ++yyp) {
879  if ((yyp[0] == '%') && (yyp[1] == 's') && (yyi < yycount))
880  {
881  yyres += yytnamerr_(yyarg[yyi++]);
882  ++yyp;
883  } else
884  yyres += *yyp;
885  }
886  return yyres;
887  }
888 
889 
890  /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
891  STATE-NUM. */
892  const signed char parser::yypact_ninf_ = -11;
893  const signed char
894  parser::yypact_[] =
895  {
896  2, -10, -11, 2, 2, 2, 4, 28, 2, 8,
897  8, 10, -11, 2, 2, 2, 2, 2, 19, -11,
898  30, 30, 8, 8, 8, -11
899  };
900 
901  /* YYDEFACT[S] -- default reduction number in state S. Performed when
902  YYTABLE doesn't specify something else to do. Zero means the
903  default is an error. */
904  const unsigned char
906  {
907  2, 5, 4, 0, 0, 0, 0, 3, 0, 12,
908  11, 0, 1, 0, 0, 0, 0, 0, 0, 14,
909  8, 7, 9, 10, 13, 6
910  };
911 
912  /* YYPGOTO[NTERM-NUM]. */
913  const signed char
914  parser::yypgoto_[] =
915  {
916  -11, -11, -3
917  };
918 
919  /* YYDEFGOTO[NTERM-NUM]. */
920  const signed char
922  {
923  -1, 6, 7
924  };
925 
926  /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
927  positive, shift that token. If negative, reduce the rule which
928  number is the opposite. If YYTABLE_NINF_, syntax error. */
929  const signed char parser::yytable_ninf_ = -1;
930  const unsigned char
931  parser::yytable_[] =
932  {
933  9, 10, 11, 8, 12, 18, 1, 2, 3, 4,
934  20, 21, 22, 23, 24, 5, 13, 14, 15, 16,
935  17, 0, 17, 0, 19, 13, 14, 15, 16, 0,
936  0, 17, 0, 25, 13, 14, 15, 16, 15, 16,
937  17, 0, 17
938  };
939 
940  /* YYCHECK. */
941  const signed char
942  parser::yycheck_[] =
943  {
944  3, 4, 5, 13, 0, 8, 4, 5, 6, 7,
945  13, 14, 15, 16, 17, 13, 6, 7, 8, 9,
946  12, -1, 12, -1, 14, 6, 7, 8, 9, -1,
947  -1, 12, -1, 14, 6, 7, 8, 9, 8, 9,
948  12, -1, 12
949  };
950 
951  /* STOS_[STATE-NUM] -- The (internal number of the) accessing
952  symbol of state STATE-NUM. */
953  const unsigned char
954  parser::yystos_[] =
955  {
956  0, 4, 5, 6, 7, 13, 16, 17, 13, 17,
957  17, 17, 0, 6, 7, 8, 9, 12, 17, 14,
958  17, 17, 17, 17, 17, 14
959  };
960 
961 #if YYDEBUG
962  /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
963  to YYLEX-NUM. */
964  const unsigned short int
966  {
967  0, 256, 257, 258, 259, 260, 45, 43, 42, 47,
968  261, 262, 94, 40, 41
969  };
970 #endif
971 
972  /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
973  const unsigned char
974  parser::yyr1_[] =
975  {
976  0, 15, 16, 16, 17, 17, 17, 17, 17, 17,
977  17, 17, 17, 17, 17
978  };
979 
980  /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
981  const unsigned char
982  parser::yyr2_[] =
983  {
984  0, 2, 0, 1, 1, 1, 4, 3, 3, 3,
985  3, 2, 2, 3, 3
986  };
987 
988 
989  /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
990  First, the terminals, then, starting at \a yyntokens_, nonterminals. */
991  const char *
992  const parser::yytname_[] =
993  {
994  "$end", "error", "$undefined", "EOL", "IDENTIFIER", "NUMBER", "'-'",
995  "'+'", "'*'", "'/'", "NEG", "PLS", "'^'", "'('","')'","$accept",
996  "line", "expr", YY_NULL
997  };
998 
999 #if YYDEBUG
1000  /* YYRHS -- A `-1'-separated list of the rules' RHS. */
1002  parser::yyrhs_[] =
1003  {
1004  16, 0, -1, -1, 17, -1, 5, -1, 4, -1,
1005  4, 13, 17, 14, -1, 17, 7, 17, -1, 17,
1006  6, 17, -1, 17, 8, 17, -1, 17, 9, 17,
1007  -1, 7, 17, -1, 6, 17, -1, 17, 12, 17,
1008  -1, 13, 17, 14, -1
1009  };
1010 
1011  /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
1012  YYRHS. */
1013  const unsigned char
1014  parser::yyprhs_[] =
1015  {
1016  0, 0, 3, 4, 6, 8, 10, 15, 19, 23,
1017  27, 31, 34, 37, 41
1018  };
1019 
1020  /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
1021  const unsigned char
1022  parser::yyrline_[] =
1023  {
1024  0, 48, 48, 49, 51, 52, 53, 54, 55, 56,
1025  57, 58, 59, 60, 61
1026  };
1027 
1028  // Print the state stack on the debug stream.
1029  void
1031  {
1032  *yycdebug_ << "Stack now";
1034  i != yystate_stack_.end(); ++i) {
1035  *yycdebug_ << ' ' << *i;
1036  }
1037  *yycdebug_ << std::endl;
1038  }
1039 
1040 
1041  // Report on the debug stream that the rule \a yyrule is going to be reduced.
1042  void
1044  {
1045  unsigned int yylno = yyrline_[yyrule];
1046  int yynrhs = yyr2_[yyrule];
1047 
1048  /* Print the symbols being reduced, and their result. */
1049  *yycdebug_ << "Reducing stack by rule " << yyrule - 1
1050  << " (line " << yylno << "):" << std::endl;
1051  /* The symbols being reduced. */
1052  for (int yyi = 0; yyi < yynrhs; yyi++) {
1053  YY_SYMBOL_PRINT(" $" << yyi + 1 << " =",
1054  yyrhs_[yyprhs_[yyrule] + yyi],
1055  &(yysemantic_stack_[(yynrhs) - (yyi + 1)]),
1056  &(yylocation_stack_[(yynrhs) - (yyi + 1)]));
1057  }
1058  }
1059 #endif // YYDEBUG
1060 
1061  /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
1064  {
1065  static
1066  const token_number_type
1067  translate_table[] =
1068  {
1069  0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1070  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1071  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1072  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1073  13, 14, 8, 7, 2, 6, 2, 9, 2, 2,
1074  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1075  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1076  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1077  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1078  2, 2, 2, 2, 12, 2, 2, 2, 2, 2,
1079  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1080  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1081  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1082  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1083  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1084  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1085  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1086  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1087  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1088  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1089  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1090  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1091  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1092  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1093  2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1094  2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
1095  5, 10, 11
1096  };
1097 
1098  if ((unsigned int)t <= yyuser_token_number_max_)
1099  return translate_table[t];
1100  else
1101  return yyundef_token_;
1102  }
1103 
1104 
1105  const int parser::yyeof_ = 0;
1106  const int parser::yylast_ = 42;
1107  const int parser::yynnts_ = 3;
1108  const int parser::yyempty_ = -2;
1109  const int parser::yyfinal_ = 12;
1110  const int parser::yyterror_ = 1;
1111  const int parser::yyerrcode_ = 256;
1112  const int parser::yyntokens_ = 15;
1113 
1114  const unsigned int parser::yyuser_token_number_max_ = 262;
1116 
1117 /* Line 1141 of lalr1.cc */
1118 #line 4 "evalexpr_parser.yy"
1119 } // yy
1120 /* Line 1141 of lalr1.cc */
1121 #line 1085 "evalexpr_parser.cpp"
1122 /* Line 1142 of lalr1.cc */
1123 #line 63 "evalexpr_parser.yy"
1124 
1125 
1126 void
1127 yy::parser::error(const yy::parser::location_type& l, const std::string& m)
1128 {
1129  driver.error(m);
1130 }
#define YYABORT
static const signed char yypgoto_[]
void error(const std::string &msg)
Definition: evalexpr.cpp:223
static const rhs_number_type yyrhs_[]
A `-1'-separated list of the rules' RHS.
static const char *const yytname_[]
For a symbol, its name in clear.
static const unsigned char yystos_[]
For a state, its accessing symbol.
#define YY_STACK_PRINT()
void set_debug_stream(std::ostream &)
Set the current debugging stream.
virtual std::string yysyntax_error_(int yystate, int tok)
static const signed char yytable_ninf_
state_stack_type yystate_stack_
The state stack.
function_t get_symbol_function(char const *name)
Definition: evalexpr.cpp:216
int debug_level_type
Type for debugging levels.
void yydestruct_(const char *yymsg, int yytype, semantic_type *yyvaluep, location_type *yylocationp)
Reclaim the memory associated to a symbol.
virtual void yy_symbol_print_(int yytype, const semantic_type *yyvaluep, const location_type *yylocationp)
Report a symbol on the debug stream.
std::ostream & debug_stream() const
The current debugging stream.
virtual int parse()
int yylex(EvalExpr::semantic_type *yylval, EvalExpr &driver)
Definition: evalexpr.cpp:65
#define YY_NULL
Definition: position.hh:49
#define YY_(msgid)
static const unsigned char yydefact_[]
std::deque< state_type >::const_reverse_iterator const_iterator
Definition: stack.hh:54
virtual ~parser()
signed char rhs_number_type
A type to store symbol numbers and -1.
static std::string yytnamerr_(const char *n)
Convert the symbol name n to a form suitable for a diagnostic.
#define YYLLOC_DEFAULT(Current, Rhs, N)
debug_level_type debug_level() const
The current debugging level.
virtual void yy_symbol_value_print_(int yytype, const semantic_type *yyvaluep, const location_type *yylocationp)
Report a symbol value on the debug stream.
#define YYCDEBUG
void push(const T &t)
Definition: stack.hh:80
static const unsigned char yytable_[]
static const int yyeof_
static const unsigned char yyprhs_[]
For each rule, the index of the first RHS symbol in yyrhs_.
void set_debug_level(debug_level_type l)
Set the current debugging level.
Symbol semantic values.
parser(EvalExpr &driver_yyarg)
Build a parser object.
static const unsigned short int yytoken_number_[]
For each scanner token number, its symbol number.
static const unsigned char yyr1_[]
For a rule, its LHS.
EvalExpr class for algebraic expression in parameter strings.
Definition: evalexpr.h:39
#define YY_REDUCE_PRINT(Rule)
virtual void error(const location_type &loc, const std::string &msg)
unsigned int height() const
Definition: stack.hh:95
virtual void yystack_print_()
Print the state stack on the debug stream.
void yypop_(unsigned int n=1)
Pop n symbols the three stacks.
stack< location_type > location_stack_type
location stack type.
#define YYUSE(e)
static const unsigned char yyrline_[]
For each rule, its source line number.
virtual void yy_reduce_print_(int r)
Report on the debug stream that the rule r is going to be reduced.
static const int yynnts_
static bool yy_table_value_is_error_(int yyvalue)
static const signed char yypact_ninf_
static const int yyntokens_
std::ostream * yycdebug_
Present a slice of the top of a stack.
Definition: stack.hh:109
#define YYDEBUG
static const signed char yycheck_[]
static const int yyfinal_
stack< semantic_type > semantic_stack_type
Semantic value stack type.
token_number_type yytranslate_(int t)
Convert a scanner token number t to a symbol number.
double get_symbol_value(char const *name)
Definition: evalexpr.cpp:209
#define YYCASE_(N, S)
void set_result(double result)
Definition: evalexpr.cpp:200
Abstract a location.
Definition: location.hh:50
static const token_number_type yyundef_token_
static const unsigned char yyr2_[]
For a rule, its RHS length.
stack< state_type > state_stack_type
State stack type.
static const signed char yydefgoto_[]
static const int yyerrcode_
const_iterator begin() const
Definition: stack.hh:100
const_iterator end() const
Definition: stack.hh:101
void pop(unsigned int n=1)
Definition: stack.hh:87
#define YY_SYMBOL_PRINT(Title, Type, Value, Location)
EvalExpr & driver
location_stack_type yylocation_stack_
The location stack.
static const unsigned int yyuser_token_number_max_
static const signed char yypact_[]
For a state, the index in yytable_ of its portion.
static bool yy_pact_value_is_default_(int yyvalue)
static const int yylast_
unsigned char token_number_type
Internal symbol numbers.
static const int yyterror_
static const int yyempty_
semantic_stack_type yysemantic_stack_
The semantic value stack.