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