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