1 #output "b4_output_prefix[]b4_output_infix[]-class.hh"
4 /* A Bison parser, made from b4_filename,
5 by GNU bison b4_version. */
7 /* Skeleton output parser for bison,
8 Copyright 1984, 1989, 1990, 2000, 2001 Free Software Foundation, Inc.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
25 /* As a special exception, when this file is copied by Bison into a
26 Bison output file, you may use that output file without restriction.
27 This special exception was added by the Free Software Foundation
28 in version 1.24 of Bison. */
31 #include "location.hh"
35 /* Enabling traces. */
37 # define YYDEBUG b4_debug
40 /* Enabling verbose error message. */
41 #ifndef YYERROR_VERBOSE
42 # define YYERROR_VERBOSE b4_error_verbose
45 /* Using locations. */
46 #define YYLSP_NEEDED b4_locations_flag
50 // FIXME: This should be defined in traits, not here.
51 typedef b4_stype yystype
;
57 template < typename P
>
63 struct Traits
< b4_name
>
65 typedef int StateType
;
66 typedef yystype SemanticType
;
67 typedef b4_ltype LocationType
;
77 typedef Traits
< b4_name
>::StateType StateType
;
78 typedef Traits
< b4_name
>::SemanticType SemanticType
;
79 typedef Traits
< b4_name
>::LocationType LocationType
;
81 typedef Stack
< StateType
> StateStack
;
82 typedef Stack
< SemanticType
> SemanticStack
;
83 typedef Stack
< LocationType
> LocationStack
;
87 LocationType initlocation
) : debug_ (debug
),
88 initlocation_ (initlocation
)
90 b4_name (bool debug
) : debug_ (debug
)
103 virtual void lex_ ();
104 virtual void error_ ();
105 virtual void print_ ();
108 StateStack state_stack_
;
109 SemanticStack semantic_stack_
;
110 LocationStack location_stack_
;
113 static const short pact_
[[]];
114 static const short defact_
[[]];
115 static const short pgoto_
[[]];
116 static const short defgoto_
[[]];
117 static const short table_
[[]];
118 static const short check_
[[]];
119 static const short r1_
[[]];
120 static const short r2_
[[]];
122 #if YYDEBUG || YYERROR_VERBOSE
123 static const char* const name_
[[]];
126 /* More tables, for debugging. */
128 static const short rhs_
[[]];
129 static const short prhs_
[[]];
130 static const short rline_
[[]];
133 /* Even more tables. */
134 static inline char translate_ (int token
);
137 static const int eof_
;
138 static const int last_
;
139 static const int flag_
;
140 static const int nnts_
;
141 static const int nsym_
;
142 static const int empty_
;
143 static const int final_
;
144 static const int terror_
;
145 static const int errcode_
;
146 static const int ntokens_
;
147 static const int initdepth_
;
148 static const unsigned maxtok_
;
156 /* Lookahead and lookahead in internal form. */
165 LocationType location
;
167 /* Initial location. */
168 LocationType initlocation_
;
172 #output "b4_output_prefix[]b4_output_infix[].cc"
173 #include "b4_output_prefix[]b4_output_infix-class.hh"
175 /* Enable debugging if requested. */
178 # define YYFPRINTF std::fprintf
179 # define YYDPRINTF(Args) \
185 # define YYDPRINTF(Args)
186 #endif /* !YYDEBUG */
192 yy::b4_name::parse ()
197 /* Initialize stack. */
198 state_stack_
= StateStack (0);
199 semantic_stack_
= SemanticStack (1);
200 location_stack_
= LocationStack (1);
202 /* Reserve initial space. The C parser needed that, but is it really
204 state_stack_
.reserve (initdepth_
);
205 semantic_stack_
.reserve (initdepth_
);
206 location_stack_
.reserve (initdepth_
);
212 location
= initlocation_
;
214 YYDPRINTF ((stderr
, "Starting parse\n"));
218 state_stack_
.push (state_
);
219 YYDPRINTF ((stderr
, "Entering state %d\n", state_
));
225 /* Try to take a decision without lookahead. */
226 n_
= pact_
[[state_]];
230 /* Read a lookahead token. */
231 if (looka_
== empty_
)
233 YYDPRINTF ((stderr
, "Reading a token: "));
237 /* Convert token to internal form. */
242 YYDPRINTF ((stderr
, "Now at end of input.\n"));
246 ilooka_
= translate_ (looka_
);
250 YYFPRINTF (stderr
, "Next token is %d (%s", looka_
, name_
[[ilooka_]]);
252 YYFPRINTF (stderr
, ")\n");
258 if (n_
< 0 || n_
> last_
|| check_
[[n_]] != ilooka_
)
261 /* Reduce or error. */
280 /* Shift the lookahead token. */
281 YYDPRINTF ((stderr
, "Shifting token %d (%s), ", looka_
, name_
[[ilooka_]]));
283 /* Discard the token being shifted unless it is eof. */
287 semantic_stack_
.push (value
);
288 location_stack_
.push (location
);
290 /* Count tokens shifted since error; after three, turn off error
298 /* Default action. */
300 n_
= defact_
[[state_]];
310 value
= semantic_stack_
[[1 - len_
]];
311 location
= location_stack_
[[1 - len_
]];
315 value
= semantic_stack_
[[0]];
316 location
= location_stack_
[[0]];
322 YYFPRINTF (stderr
, "Reducing via rule %d (line %d), ", n_
- 1, rline_
[[n_]]);
323 for (unsigned i
= prhs_
[[n_]];
325 YYFPRINTF (stderr
, "%s ", name_
[[rhs_
[i
]]]);
326 YYFPRINTF (stderr
, "-> %s\n", name_
[[r1_
[n_
]]]);
331 SemanticType
& yyval (value
);
332 LocationType
& yyloc (location
);
333 SemanticStack
& yyvsp (semantic_stack_
);
334 LocationStack
& yylsp (location_stack_
);
342 state_stack_
.pop (len_
);
343 semantic_stack_
.pop (len_
);
344 location_stack_
.pop (len_
);
349 YYFPRINTF (stderr
, "state stack now");
350 for (StateStack::ConstIterator i
= state_stack_
.begin ();
351 i
!= state_stack_
.end (); ++i
)
352 YYFPRINTF (stderr
, " %d", *i
);
353 YYFPRINTF (stderr
, "\n");
357 semantic_stack_
.push (value
);
358 location_stack_
.push (location
);
360 /* Shift the result of the reduction. */
362 state_
= pgoto_
[[n_
- ntokens_
]] + state_stack_
[[0]];
363 if (state_
>= 0 && state_
<= last_
&& check_
[[state_]] == state_stack_
[[0]])
364 state_
= table_
[[state_]];
366 state_
= defgoto_
[[n_
- ntokens_
]];
369 /* Report and recover from errors. This is very incomplete. */
371 /* If not already recovering from an error, report this error. */
377 n_
= pact_
[[state_]];
378 if (n_
> flag_
&& n_
< last_
)
380 message
= "parse error, unexpected ";
381 message
+= name_
[[ilooka_]];
384 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
385 if (check_
[[x
+ n_
]] == x
)
390 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
391 if (check_
[[x
+ n_
]] == x
)
393 message
+= (!count
++) ? ", expecting " : " or ";
394 message
+= name_
[[x]];
401 message
= "parse error";
406 /* Error raised explicitly by an action. */
410 /* If just tried and failed to reuse lookahead token after an
411 error, discard it. */
413 /* Return failure if at end of input. */
416 YYDPRINTF ((stderr
, "Discarding token %d (%s).\n", looka_
, name_
[[ilooka_]]));
420 /* Else will try to reuse lookahead token after shifting the error
426 /* Pop the current state because it cannot handle the error token. */
429 if (!state_stack_
.height ())
431 state_
= (state_stack_
.pop (), state_stack_
[[0]]);
432 semantic_stack_
.pop ();
433 location_stack_
.pop ();;
438 YYFPRINTF (stderr
, "Error: state stack now");
439 for (StateStack::ConstIterator i
= state_stack_
.begin ();
440 i
!= state_stack_
.end (); ++i
)
441 YYFPRINTF (stderr
, " %d", *i
);
442 YYFPRINTF (stderr
, "\n");
447 n_
= pact_
[[state_]];
452 if (n_
< 0 || n_
> last_
|| check_
[[n_]] != terror_
)
469 YYDPRINTF ((stderr
, "Shifting error token, "));
471 semantic_stack_
.push (value
);
472 location_stack_
.push (location
);
490 looka_
= yylex (&value
, &location
);
492 looka_
= yylex (&value
);
496 /* YYPACT[[STATE-NUM]] -- Index in YYTABLE of the portion describing
499 yy::b4_name::pact_
[[]] =
504 /* YYDEFACT[[S]] -- default rule to reduce with in state S when YYTABLE
505 doesn't specify something else to do. Zero means the default is an
508 yy::b4_name::defact_
[[]] =
513 /* YYPGOTO[[NTERM-NUM]]. */
515 yy::b4_name::pgoto_
[[]] =
520 /* YYDEFGOTO[[NTERM-NUM]]. */
522 yy::b4_name::defgoto_
[[]] =
527 /* YYTABLE[[YYPACT[STATE-NUM]]]. What to do in state STATE-NUM. If
528 positive, shift that token. If negative, reduce the rule which
529 number is the opposite. If zero, do what YYDEFACT says. */
531 yy::b4_name::table_
[[]] =
538 yy::b4_name::check_
[[]] =
543 /* YYR1[[YYN]] -- Symbol number of symbol that rule YYN derives. */
545 yy::b4_name::r1_
[[]] =
550 /* YYR2[[YYN]] -- Number of symbols composing right hand side of rule YYN. */
552 yy::b4_name::r2_
[[]] =
557 #if YYDEBUG || YYERROR_VERBOSE
558 /* YYTNAME[[SYMBOL-NUM]] -- String name of the symbol SYMBOL-NUM.
559 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
561 const yy::b4_name::name_
[[]] =
568 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
570 yy::b4_name::rhs_
[[]] =
575 /* YYPRHS[[YYN]] -- Index of the first RHS symbol of rule number YYN in
578 yy::b4_name::prhs_
[[]] =
583 /* YYRLINE[[YYN]] -- source line where rule number YYN was defined. */
585 yy::b4_name::rline_
[[]] =
591 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
593 yy::b4_name::translate_ (int token
)
601 return ((unsigned)(token
) <= maxtok_
? translate_
[[token]] : nsym_
);
604 const int yy::b4_name::eof_
= 0;
605 const int yy::b4_name::last_
= b4_last
;
606 const int yy::b4_name::flag_
= b4_flag
;
607 const int yy::b4_name::nnts_
= b4_nnts
;
608 const int yy::b4_name::nsym_
= b4_nsym
;
609 const int yy::b4_name::empty_
= -2;
610 const int yy::b4_name::final_
= b4_final
;
611 const int yy::b4_name::terror_
= 1;
612 const int yy::b4_name::errcode_
= 256;
613 const int yy::b4_name::ntokens_
= b4_ntokens
;
614 const int yy::b4_name::initdepth_
= b4_initdepth
;
616 const unsigned yy::b4_name::maxtok_
= b4_maxtok
;
621 #ifndef BISON_STACK_HH
622 # define BISON_STACK_HH
628 template < class T
, class S
= std::vector
< T
> >
633 typedef typename
S::iterator Iterator
;
634 typedef typename
S::const_iterator ConstIterator
;
640 Stack (unsigned n
) : seq_ (n
)
646 operator [[]] (int index
)
648 return seq_
[[seq_
.size () - 1 + index
]];
653 operator [[]] (int index
) const
655 return seq_
[[seq_
.size () - 1 + index
]];
687 inline ConstIterator
begin () const { return seq_
.begin (); }
688 inline ConstIterator
end () const { return seq_
.end (); }
696 #endif // not BISON_STACK_HH
698 #output "location.hh"
699 #ifndef BISON_LOCATION_HH
700 # define BISON_LOCATION_HH
717 #endif // not BISON_LOCATION_HH
719 m4_if(b4_defines_flag
, 0, [],
720 [#output "b4_output_header_name"
721 #ifndef b4_header_guard
722 # define b4_header_guard
729 # define YYSTYPE yystype
733 [extern YYSTYPE b4_prefix
[]lval
;])
735 m4_if(b4_locations_flag
, [0], [],
737 typedef struct yyltype
744 # define YYLTYPE yyltype
748 [extern YYLTYPE b4_prefix
[]lloc
;])
750 #endif /* not b4_header_guard */