3 # m4_define_default(MACRO, VALUE)
4 # -------------------------------
5 # Define MACRO to VALUE, unless already defined.
6 m4_define([m4_define_default
],
7 [m4_ifdef([$
1], [], [m4_define($@
)])])
9 m4_define_default([b4_input_suffix
], [.y
])
11 m4_define_default([b4_output_parser_suffix
],
12 [m4_translit(b4_input_suffix
, [yY
], [cC
])])
14 m4_define_default([b4_output_parser_name
],
15 [b4_output_prefix
[]b4_output_infix
[]b4_output_parser_suffix
[]])
18 m4_define_default([b4_output_header_suffix
],
19 [m4_translit(b4_input_suffix
, [yY
], [hH
])])
21 m4_define_default([b4_output_header_name
],
22 [b4_output_prefix
[]b4_output_infix
[]b4_output_header_suffix
[]])
24 m4_define_default([b4_header_guard
],
25 [m4_bpatsubst(m4_toupper([BISON_
]b4_output_header_name
),
26 [[^ABCDEFGHIJKLMNOPQRSTUVWXYZ
]], [_
])])
28 m4_define([b4_copyright
],
30 /* A Bison parser, made from b4_filename,
31 by GNU bison b4_version. */
33 /* Skeleton output parser for bison,
34 Copyright 2002 Free Software Foundation, Inc.
36 This program is free software; you can redistribute it and/or modify
37 it under the terms of the GNU General Public License as published by
38 the Free Software Foundation; either version 2, or (at your option)
41 This program is distributed in the hope that it will be useful,
42 but WITHOUT ANY WARRANTY; without even the implied warranty of
43 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44 GNU General Public License for more details.
46 You should have received a copy of the GNU General Public License
47 along with this program; if not, write to the Free Software
48 Foundation, Inc., 59 Temple Place - Suite 330,
49 Boston, MA 02111-1307, USA. */
51 /* As a special exception, when this file is copied by Bison into a
52 Bison output file, you may use that output file without restriction.
53 This special exception was added by the Free Software Foundation
54 in version 1.24 of Bison. */])
57 #output "b4_output_header_name"
59 #ifndef b4_header_guard
60 # define b4_header_guard
63 #include "location.hh"
67 /* Using locations. */
68 #define YYLSP_NEEDED b4_locations_flag
75 /* Enabling traces. */
77 # define YYDEBUG b4_debug
80 /* Enabling verbose error message. */
81 #ifndef YYERROR_VERBOSE
82 # define YYERROR_VERBOSE b4_error_verbose
88 # define YYSTYPE yystype
91 m4_if(b4_locations_flag
, [0], [],
93 typedef struct yyltype
100 # define YYLTYPE yyltype
107 template < typename P
>
113 struct Traits
< b4_name
>
115 typedef int StateType
;
116 typedef yystype SemanticType
;
117 typedef b4_ltype LocationType
;
127 typedef Traits
< b4_name
>::StateType StateType
;
128 typedef Traits
< b4_name
>::SemanticType SemanticType
;
129 typedef Traits
< b4_name
>::LocationType LocationType
;
131 typedef Stack
< StateType
> StateStack
;
132 typedef Stack
< SemanticType
> SemanticStack
;
133 typedef Stack
< LocationType
> LocationStack
;
137 LocationType initlocation
) : debug_ (debug
),
138 initlocation_ (initlocation
)
140 b4_name (bool debug
) : debug_ (debug
)
149 virtual int parse ();
153 virtual void lex_ ();
154 virtual void error_ ();
155 virtual void print_ ();
158 StateStack state_stack_
;
159 SemanticStack semantic_stack_
;
160 LocationStack location_stack_
;
163 static const short pact_
[[]];
164 static const short defact_
[[]];
165 static const short pgoto_
[[]];
166 static const short defgoto_
[[]];
167 static const short table_
[[]];
168 static const short check_
[[]];
169 static const short r1_
[[]];
170 static const short r2_
[[]];
172 #if YYDEBUG || YYERROR_VERBOSE
173 static const char* const name_
[[]];
176 /* More tables, for debugging. */
178 static const short rhs_
[[]];
179 static const short prhs_
[[]];
180 static const short rline_
[[]];
183 /* Even more tables. */
184 static inline char translate_ (int token
);
187 static const int eof_
;
188 static const int last_
;
189 static const int flag_
;
190 static const int nnts_
;
191 static const int nsym_
;
192 static const int empty_
;
193 static const int final_
;
194 static const int terror_
;
195 static const int errcode_
;
196 static const int ntokens_
;
197 static const int initdepth_
;
198 static const unsigned maxtok_
;
206 /* Lookahead and lookahead in internal form. */
215 LocationType location
;
217 /* Initial location. */
218 LocationType initlocation_
;
222 #endif /* not b4_header_guard */
224 #output "b4_output_prefix[]b4_output_infix[].cc"
227 #include "b4_output_header_name"
229 /* Enable debugging if requested. */
232 # define YYFPRINTF std::fprintf
233 # define YYDPRINTF(Args) \
239 # define YYDPRINTF(Args)
240 #endif /* !YYDEBUG */
243 yy::b4_name::parse ()
248 /* Initialize stack. */
249 state_stack_
= StateStack (0);
250 semantic_stack_
= SemanticStack (1);
251 location_stack_
= LocationStack (1);
253 /* Reserve initial space. The C parser needed that, but is it really
255 state_stack_
.reserve (initdepth_
);
256 semantic_stack_
.reserve (initdepth_
);
257 location_stack_
.reserve (initdepth_
);
263 location
= initlocation_
;
265 YYDPRINTF ((stderr
, "Starting parse\n"));
269 state_stack_
.push (state_
);
270 YYDPRINTF ((stderr
, "Entering state %d\n", state_
));
276 /* Try to take a decision without lookahead. */
277 n_
= pact_
[[state_]];
281 /* Read a lookahead token. */
282 if (looka_
== empty_
)
284 YYDPRINTF ((stderr
, "Reading a token: "));
288 /* Convert token to internal form. */
293 YYDPRINTF ((stderr
, "Now at end of input.\n"));
297 ilooka_
= translate_ (looka_
);
301 YYFPRINTF (stderr
, "Next token is %d (%s", looka_
, name_
[[ilooka_]]);
303 YYFPRINTF (stderr
, ")\n");
309 if (n_
< 0 || n_
> last_
|| check_
[[n_]] != ilooka_
)
312 /* Reduce or error. */
331 /* Shift the lookahead token. */
332 YYDPRINTF ((stderr
, "Shifting token %d (%s), ", looka_
, name_
[[ilooka_]]));
334 /* Discard the token being shifted unless it is eof. */
338 semantic_stack_
.push (value
);
339 location_stack_
.push (location
);
341 /* Count tokens shifted since error; after three, turn off error
349 /* Default action. */
351 n_
= defact_
[[state_]];
361 value
= semantic_stack_
[[1 - len_
]];
362 location
= location_stack_
[[1 - len_
]];
366 value
= semantic_stack_
[[0]];
367 location
= location_stack_
[[0]];
373 YYFPRINTF (stderr
, "Reducing via rule %d (line %d), ", n_
- 1, rline_
[[n_]]);
374 for (unsigned i
= prhs_
[[n_]];
376 YYFPRINTF (stderr
, "%s ", name_
[[rhs_
[i
]]]);
377 YYFPRINTF (stderr
, "-> %s\n", name_
[[r1_
[n_
]]]);
382 SemanticType
& yyval (value
);
383 LocationType
& yyloc (location
);
384 SemanticStack
& yyvsp (semantic_stack_
);
385 LocationStack
& yylsp (location_stack_
);
393 state_stack_
.pop (len_
);
394 semantic_stack_
.pop (len_
);
395 location_stack_
.pop (len_
);
400 YYFPRINTF (stderr
, "state stack now");
401 for (StateStack::ConstIterator i
= state_stack_
.begin ();
402 i
!= state_stack_
.end (); ++i
)
403 YYFPRINTF (stderr
, " %d", *i
);
404 YYFPRINTF (stderr
, "\n");
408 semantic_stack_
.push (value
);
409 location_stack_
.push (location
);
411 /* Shift the result of the reduction. */
413 state_
= pgoto_
[[n_
- ntokens_
]] + state_stack_
[[0]];
414 if (state_
>= 0 && state_
<= last_
&& check_
[[state_]] == state_stack_
[[0]])
415 state_
= table_
[[state_]];
417 state_
= defgoto_
[[n_
- ntokens_
]];
420 /* Report and recover from errors. This is very incomplete. */
422 /* If not already recovering from an error, report this error. */
428 n_
= pact_
[[state_]];
429 if (n_
> flag_
&& n_
< last_
)
431 message
= "parse error, unexpected ";
432 message
+= name_
[[ilooka_]];
435 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
436 if (check_
[[x
+ n_
]] == x
)
441 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
442 if (check_
[[x
+ n_
]] == x
)
444 message
+= (!count
++) ? ", expecting " : " or ";
445 message
+= name_
[[x]];
452 message
= "parse error";
457 /* Error raised explicitly by an action. */
461 /* If just tried and failed to reuse lookahead token after an
462 error, discard it. */
464 /* Return failure if at end of input. */
467 YYDPRINTF ((stderr
, "Discarding token %d (%s).\n", looka_
, name_
[[ilooka_]]));
471 /* Else will try to reuse lookahead token after shifting the error
477 /* Pop the current state because it cannot handle the error token. */
480 if (!state_stack_
.height ())
482 state_
= (state_stack_
.pop (), state_stack_
[[0]]);
483 semantic_stack_
.pop ();
484 location_stack_
.pop ();;
489 YYFPRINTF (stderr
, "Error: state stack now");
490 for (StateStack::ConstIterator i
= state_stack_
.begin ();
491 i
!= state_stack_
.end (); ++i
)
492 YYFPRINTF (stderr
, " %d", *i
);
493 YYFPRINTF (stderr
, "\n");
498 n_
= pact_
[[state_]];
503 if (n_
< 0 || n_
> last_
|| check_
[[n_]] != terror_
)
520 YYDPRINTF ((stderr
, "Shifting error token, "));
522 semantic_stack_
.push (value
);
523 location_stack_
.push (location
);
541 looka_
= yylex (&value
, &location
);
543 looka_
= yylex (&value
);
547 /* YYPACT[[STATE-NUM]] -- Index in YYTABLE of the portion describing
550 yy::b4_name::pact_
[[]] =
555 /* YYDEFACT[[S]] -- default rule to reduce with in state S when YYTABLE
556 doesn't specify something else to do. Zero means the default is an
559 yy::b4_name::defact_
[[]] =
564 /* YYPGOTO[[NTERM-NUM]]. */
566 yy::b4_name::pgoto_
[[]] =
571 /* YYDEFGOTO[[NTERM-NUM]]. */
573 yy::b4_name::defgoto_
[[]] =
578 /* YYTABLE[[YYPACT[STATE-NUM]]]. What to do in state STATE-NUM. If
579 positive, shift that token. If negative, reduce the rule which
580 number is the opposite. If zero, do what YYDEFACT says. */
582 yy::b4_name::table_
[[]] =
589 yy::b4_name::check_
[[]] =
594 /* YYR1[[YYN]] -- Symbol number of symbol that rule YYN derives. */
596 yy::b4_name::r1_
[[]] =
601 /* YYR2[[YYN]] -- Number of symbols composing right hand side of rule YYN. */
603 yy::b4_name::r2_
[[]] =
608 #if YYDEBUG || YYERROR_VERBOSE
609 /* YYTNAME[[SYMBOL-NUM]] -- String name of the symbol SYMBOL-NUM.
610 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
612 const yy::b4_name::name_
[[]] =
619 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
621 yy::b4_name::rhs_
[[]] =
626 /* YYPRHS[[YYN]] -- Index of the first RHS symbol of rule number YYN in
629 yy::b4_name::prhs_
[[]] =
634 /* YYRLINE[[YYN]] -- source line where rule number YYN was defined. */
636 yy::b4_name::rline_
[[]] =
642 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
644 yy::b4_name::translate_ (int token
)
652 return ((unsigned)(token
) <= maxtok_
? translate_
[[token]] : nsym_
);
655 const int yy::b4_name::eof_
= 0;
656 const int yy::b4_name::last_
= b4_last
;
657 const int yy::b4_name::flag_
= b4_flag
;
658 const int yy::b4_name::nnts_
= b4_nnts
;
659 const int yy::b4_name::nsym_
= b4_nsym
;
660 const int yy::b4_name::empty_
= -2;
661 const int yy::b4_name::final_
= b4_final
;
662 const int yy::b4_name::terror_
= 1;
663 const int yy::b4_name::errcode_
= 256;
664 const int yy::b4_name::ntokens_
= b4_ntokens
;
665 const int yy::b4_name::initdepth_
= b4_initdepth
;
667 const unsigned yy::b4_name::maxtok_
= b4_maxtok
;
674 #ifndef BISON_STACK_HH
675 # define BISON_STACK_HH
681 template < class T
, class S
= std::vector
< T
> >
686 typedef typename
S::iterator Iterator
;
687 typedef typename
S::const_iterator ConstIterator
;
693 Stack (unsigned n
) : seq_ (n
)
699 operator [[]] (int index
)
701 return seq_
[[seq_
.size () - 1 + index
]];
706 operator [[]] (int index
) const
708 return seq_
[[seq_
.size () - 1 + index
]];
740 inline ConstIterator
begin () const { return seq_
.begin (); }
741 inline ConstIterator
end () const { return seq_
.end (); }
749 #endif // not BISON_STACK_HH
751 #output "location.hh"
754 #ifndef BISON_LOCATION_HH
755 # define BISON_LOCATION_HH
772 #endif // not BISON_LOCATION_HH