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