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
48 // FIXME: This should be defined in traits, not here.
49 typedef b4_stype yystype
;
55 template < typename P
>
61 struct Traits
< b4_name
>
63 typedef int StateType
;
64 typedef yystype SemanticType
;
65 typedef b4_ltype LocationType
;
75 typedef Traits
< b4_name
>::StateType StateType
;
76 typedef Traits
< b4_name
>::SemanticType SemanticType
;
77 typedef Traits
< b4_name
>::LocationType LocationType
;
79 typedef Stack
< StateType
> StateStack
;
80 typedef Stack
< SemanticType
> SemanticStack
;
81 typedef Stack
< LocationType
> LocationStack
;
83 b4_name (bool debug
) : debug_ (debug
)
96 virtual void error_ ();
97 virtual void print_ ();
100 StateStack state_stack_
;
101 SemanticStack semantic_stack_
;
102 LocationStack location_stack_
;
105 static const short pact_
[[]];
106 static const short defact_
[[]];
107 static const short pgoto_
[[]];
108 static const short defgoto_
[[]];
109 static const short table_
[[]];
110 static const short check_
[[]];
111 static const short r1_
[[]];
112 static const short r2_
[[]];
114 #if YYDEBUG || YYERROR_VERBOSE
115 static const char* const name_
[[]];
118 /* More tables, for debugging. */
120 static const short rhs_
[[]];
121 static const short prhs_
[[]];
122 static const short rline_
[[]];
125 /* Even more tables. */
126 static inline char translate_ (int token
);
129 static const int eof_
;
130 static const int last_
;
131 static const int flag_
;
132 static const int nnts_
;
133 static const int nsym_
;
134 static const int empty_
;
135 static const int final_
;
136 static const int terror_
;
137 static const int errcode_
;
138 static const int ntokens_
;
139 static const int initdepth_
;
140 static const unsigned maxtok_
;
148 /* Lookahead and lookahead in internal form. */
157 LocationType location
;
161 #output "b4_output_prefix[]b4_output_infix[].cc"
162 #include "b4_output_prefix[]b4_output_infix-class.hh"
164 /* Enable debugging if requested. */
167 # define YYFPRINTF std::fprintf
168 # define YYDPRINTF(Args) \
174 # define YYDPRINTF(Args)
175 #endif /* !YYDEBUG */
181 yy::b4_name::parse ()
186 /* Initialize stack. */
187 state_stack_
= StateStack (0);
188 semantic_stack_
= SemanticStack (1);
189 location_stack_
= LocationStack (1);
191 /* Reserve initial space. The C parser needed that, but is it really
193 state_stack_
.reserve (initdepth_
);
194 semantic_stack_
.reserve (initdepth_
);
195 location_stack_
.reserve (initdepth_
);
200 YYDPRINTF ((stderr
, "Starting parse\n"));
204 state_stack_
.push (state_
);
205 YYDPRINTF ((stderr
, "Entering state %d\n", state_
));
211 /* Try to take a decision without lookahead. */
212 n_
= pact_
[[state_]];
216 /* Read a lookahead token. */
217 if (looka_
== empty_
)
219 YYDPRINTF ((stderr
, "Reading a token: "));
223 /* Convert token to internal form. */
228 YYDPRINTF ((stderr
, "Now at end of input.\n"));
232 ilooka_
= translate_ (looka_
);
236 YYFPRINTF (stderr
, "Next token is %d (%s", looka_
, name_
[[ilooka_]]);
238 YYFPRINTF (stderr
, ")\n");
244 if (n_
< 0 || n_
> last_
|| check_
[[n_]] != ilooka_
)
247 /* Reduce or error. */
266 /* Shift the lookahead token. */
267 YYDPRINTF ((stderr
, "Shifting token %d (%s), ", looka_
, name_
[[ilooka_]]));
269 /* Discard the token being shifted unless it is eof. */
273 semantic_stack_
.push (value
);
274 location_stack_
.push (location
);
278 /* Default action. */
280 n_
= defact_
[[state_]];
290 value
= semantic_stack_
[[1 - len_
]];
291 location
= location_stack_
[[1 - len_
]];
295 value
= semantic_stack_
[[0]];
296 location
= location_stack_
[[0]];
302 YYFPRINTF (stderr
, "Reducing via rule %d (line %d), ", n_
- 1, rline_
[[n_]]);
303 for (unsigned i
= prhs_
[[n_]];
305 YYFPRINTF (stderr
, "%s ", name_
[[rhs_
[i
]]]);
306 YYFPRINTF (stderr
, "-> %s\n", name_
[[r1_
[n_
]]]);
311 SemanticType
& yyval (value
);
312 LocationType
& yyloc (location
);
313 SemanticStack
& yyvsp (semantic_stack_
);
314 LocationStack
& yylsp (location_stack_
);
322 state_stack_
.pop (len_
);
323 semantic_stack_
.pop (len_
);
324 location_stack_
.pop (len_
);
329 YYFPRINTF (stderr
, "state stack now");
330 for (StateStack::ConstIterator i
= state_stack_
.begin ();
331 i
!= state_stack_
.end (); ++i
)
332 YYFPRINTF (stderr
, " %d", *i
);
333 YYFPRINTF (stderr
, "\n");
337 semantic_stack_
.push (value
);
338 location_stack_
.push (location
);
340 /* Shift the result of the reduction. */
342 state_
= pgoto_
[[n_
- ntokens_
]] + state_stack_
[[0]];
343 if (state_
>= 0 && state_
<= last_
&& check_
[[state_]] == state_stack_
[[0]])
344 state_
= table_
[[state_]];
346 state_
= defgoto_
[[n_
- ntokens_
]];
349 /* Report and recover from errors. This is very incomplete. */
351 /* If not already recovering from an error, report this error. */
357 n_
= pact_
[[state_]];
358 if (n_
> flag_
&& n_
< last_
)
360 message
= "parse error, unexpected ";
361 message
+= name_
[[ilooka_]];
364 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
365 if (check_
[[x
+ n_
]] == x
)
370 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
371 if (check_
[[x
+ n_
]] == x
)
373 message
+= (!count
++) ? ", expecting " : " or ";
374 message
+= name_
[[x]];
381 message
= "parse error";
386 /* Error raised explicitly by an action. */
390 /* If just tried and failed to reuse lookahead token after an
391 error, discard it. */
393 /* Return failure if at end of input. */
396 YYDPRINTF ((stderr
, "Discarding token %d (%s).\n", looka_
, name_
[[ilooka_]]));
400 /* Else will try to reuse lookahead token after shifting the error
406 /* Pop the current state because it cannot handle the error token. */
409 if (!state_stack_
.height ())
411 state_
= (state_stack_
.pop (), state_stack_
[[0]]);
412 semantic_stack_
.pop ();
413 location_stack_
.pop ();;
418 YYFPRINTF (stderr
, "Error: state stack now");
419 for (StateStack::ConstIterator i
= state_stack_
.begin ();
420 i
!= state_stack_
.end (); ++i
)
421 YYFPRINTF (stderr
, " %d", *i
);
422 YYFPRINTF (stderr
, "\n");
427 n_
= pact_
[[state_]];
432 if (n_
< 0 || n_
> last_
|| check_
[[n_]] != terror_
)
449 YYDPRINTF ((stderr
, "Shifting error token, "));
451 semantic_stack_
.push (value
);
452 location_stack_
.push (location
);
470 looka_
= yylex (&value
, &location
);
472 looka_
= yylex (&value
);
476 /* YYPACT[[STATE-NUM]] -- Index in YYTABLE of the portion describing
479 yy::b4_name::pact_
[[]] =
484 /* YYDEFACT[[S]] -- default rule to reduce with in state S when YYTABLE
485 doesn't specify something else to do. Zero means the default is an
488 yy::b4_name::defact_
[[]] =
493 /* YYPGOTO[[NTERM-NUM]]. */
495 yy::b4_name::pgoto_
[[]] =
500 /* YYDEFGOTO[[NTERM-NUM]]. */
502 yy::b4_name::defgoto_
[[]] =
507 /* YYTABLE[[YYPACT[STATE-NUM]]]. What to do in state STATE-NUM. If
508 positive, shift that token. If negative, reduce the rule which
509 number is the opposite. If zero, do what YYDEFACT says. */
511 yy::b4_name::table_
[[]] =
518 yy::b4_name::check_
[[]] =
523 /* YYR1[[YYN]] -- Symbol number of symbol that rule YYN derives. */
525 yy::b4_name::r1_
[[]] =
530 /* YYR2[[YYN]] -- Number of symbols composing right hand side of rule YYN. */
532 yy::b4_name::r2_
[[]] =
537 #if YYDEBUG || YYERROR_VERBOSE
538 /* YYTNAME[[SYMBOL-NUM]] -- String name of the symbol SYMBOL-NUM.
539 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
541 const yy::b4_name::name_
[[]] =
548 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
550 yy::b4_name::rhs_
[[]] =
555 /* YYPRHS[[YYN]] -- Index of the first RHS symbol of rule number YYN in
558 yy::b4_name::prhs_
[[]] =
563 /* YYRLINE[[YYN]] -- source line where rule number YYN was defined. */
565 yy::b4_name::rline_
[[]] =
571 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
573 yy::b4_name::translate_ (int token
)
581 return ((unsigned)(token
) <= maxtok_
? translate_
[[token]] : nsym_
);
584 const int yy::b4_name::eof_
= 0;
585 const int yy::b4_name::last_
= b4_last
;
586 const int yy::b4_name::flag_
= b4_flag
;
587 const int yy::b4_name::nnts_
= b4_nnts
;
588 const int yy::b4_name::nsym_
= b4_nsym
;
589 const int yy::b4_name::empty_
= -2;
590 const int yy::b4_name::final_
= b4_final
;
591 const int yy::b4_name::terror_
= 1;
592 const int yy::b4_name::errcode_
= 256;
593 const int yy::b4_name::ntokens_
= b4_ntokens
;
594 const int yy::b4_name::initdepth_
= b4_initdepth
;
596 const unsigned yy::b4_name::maxtok_
= b4_maxtok
;
601 #ifndef BISON_STACK_HH
602 # define BISON_STACK_HH
608 template < class T
, class S
= std::vector
< T
> >
613 typedef typename
S::iterator Iterator
;
614 typedef typename
S::const_iterator ConstIterator
;
620 Stack (unsigned n
) : seq_ (n
)
626 operator [[]] (int index
)
628 return seq_
[[seq_
.size () - 1 + index
]];
633 operator [[]] (int index
) const
635 return seq_
[[seq_
.size () - 1 + index
]];
667 inline ConstIterator
begin () const { return seq_
.begin (); }
668 inline ConstIterator
end () const { return seq_
.end (); }
676 #endif // not BISON_STACK_HH
678 #output "location.hh"
679 #ifndef BISON_LOCATION_HH
680 # define BISON_LOCATION_HH
697 #endif // not BISON_LOCATION_HH
699 m4_if(b4_defines_flag
, 0, [],
700 [#output "b4_output_header_name"
701 #ifndef b4_header_guard
702 # define b4_header_guard
709 # define YYSTYPE yystype
713 [extern YYSTYPE b4_prefix
[]lval
;])
715 m4_if(b4_locations_flag
, [0], [],
717 typedef struct yyltype
724 # define YYLTYPE yyltype
728 [extern YYLTYPE b4_prefix
[]lloc
;])
730 #endif /* not b4_header_guard */