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_inherit
],
40 m4_define([b4_constructor
],
46 m4_define([b4_copyright
],
48 /* A Bison parser, made from b4_filename,
49 by GNU bison b4_version. */
51 /* Skeleton output parser for bison,
52 Copyright 2002 Free Software Foundation, Inc.
54 This program is free software; you can redistribute it and/or modify
55 it under the terms of the GNU General Public License as published by
56 the Free Software Foundation; either version 2, or (at your option)
59 This program is distributed in the hope that it will be useful,
60 but WITHOUT ANY WARRANTY; without even the implied warranty of
61 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
62 GNU General Public License for more details.
64 You should have received a copy of the GNU General Public License
65 along with this program; if not, write to the Free Software
66 Foundation, Inc., 59 Temple Place - Suite 330,
67 Boston, MA 02111-1307, USA. */
69 /* As a special exception, when this file is copied by Bison into a
70 Bison output file, you may use that output file without restriction.
71 This special exception was added by the Free Software Foundation
72 in version 1.24 of Bison. */])
75 #output "b4_output_header_name"
77 #ifndef b4_header_guard
78 # define b4_header_guard
81 #include "location.hh"
85 /* Using locations. */
86 #define YYLSP_NEEDED b4_locations_flag
93 /* Enabling traces. */
95 # define YYDEBUG b4_debug
98 /* Enabling verbose error message. */
99 #ifndef YYERROR_VERBOSE
100 # define YYERROR_VERBOSE b4_error_verbose
106 # define YYSTYPE yystype
109 #ifndef YYLLOC_DEFAULT
110 # define YYLLOC_DEFAULT(Current, Rhs, N) \
111 Current.last_line = Rhs[[N]].last_line; \
112 Current.last_column = Rhs[[N]].last_column;
115 m4_if(b4_locations_flag
, [0], [],
117 typedef struct yyltype
124 # define YYLTYPE yyltype
131 template < typename P
>
137 struct Traits
< b4_name
>
139 typedef int StateType
;
140 typedef yystype SemanticType
;
141 typedef b4_ltype LocationType
;
147 class b4_name b4_inherit
151 typedef Traits
< b4_name
>::StateType StateType
;
152 typedef Traits
< b4_name
>::SemanticType SemanticType
;
153 typedef Traits
< b4_name
>::LocationType LocationType
;
155 typedef Stack
< StateType
> StateStack
;
156 typedef Stack
< SemanticType
> SemanticStack
;
157 typedef Stack
< LocationType
> LocationStack
;
161 LocationType initlocation
[]b4_param
) :
162 b4_constructor
[]debug_ (debug
),
163 initlocation_ (initlocation
)
165 b4_name (bool debug
[]b4_param
) :
166 b4_constructor
[]debug_ (debug
)
175 virtual int parse ();
179 virtual void lex_ ();
180 virtual void error_ ();
181 virtual void print_ ();
184 StateStack state_stack_
;
185 SemanticStack semantic_stack_
;
186 LocationStack location_stack_
;
189 static const short pact_
[[]];
190 static const short defact_
[[]];
191 static const short pgoto_
[[]];
192 static const short defgoto_
[[]];
193 static const short table_
[[]];
194 static const short check_
[[]];
195 static const short r1_
[[]];
196 static const short r2_
[[]];
198 #if YYDEBUG || YYERROR_VERBOSE
199 static const char* const name_
[[]];
202 /* More tables, for debugging. */
204 static const short rhs_
[[]];
205 static const short prhs_
[[]];
206 static const short rline_
[[]];
209 /* Even more tables. */
210 static inline char translate_ (int token
);
213 static const int eof_
;
214 static const int last_
;
215 static const int flag_
;
216 static const int nnts_
;
217 static const int nsym_
;
218 static const int empty_
;
219 static const int final_
;
220 static const int terror_
;
221 static const int errcode_
;
222 static const int ntokens_
;
223 static const int initdepth_
;
224 static const unsigned maxtok_
;
232 /* Lookahead and lookahead in internal form. */
239 /* Semantic value and location of lookahead token. */
241 LocationType location
;
247 /* Initial location. */
248 LocationType initlocation_
;
252 #endif /* not b4_header_guard */
254 #output "b4_output_prefix[]b4_output_infix[].cc"
257 #include "b4_output_header_name"
259 /* Enable debugging if requested. */
262 # define YYFPRINTF std::fprintf
263 # define YYDPRINTF(Args) \
269 # define YYDPRINTF(Args)
270 #endif /* !YYDEBUG */
273 yy::b4_name::parse ()
278 /* Initialize stack. */
279 state_stack_
= StateStack (0);
280 semantic_stack_
= SemanticStack (1);
281 location_stack_
= LocationStack (1);
283 /* Reserve initial space. The C parser needed that, but is it really
285 state_stack_
.reserve (initdepth_
);
286 semantic_stack_
.reserve (initdepth_
);
287 location_stack_
.reserve (initdepth_
);
293 location
= initlocation_
;
295 YYDPRINTF ((stderr
, "Starting parse\n"));
299 state_stack_
.push (state_
);
300 YYDPRINTF ((stderr
, "Entering state %d\n", state_
));
306 /* Try to take a decision without lookahead. */
307 n_
= pact_
[[state_]];
311 /* Read a lookahead token. */
312 if (looka_
== empty_
)
314 YYDPRINTF ((stderr
, "Reading a token: "));
318 /* Convert token to internal form. */
323 YYDPRINTF ((stderr
, "Now at end of input.\n"));
327 ilooka_
= translate_ (looka_
);
331 YYFPRINTF (stderr
, "Next token is %d (%s", looka_
, name_
[[ilooka_]]);
333 YYFPRINTF (stderr
, ")\n");
339 if (n_
< 0 || n_
> last_
|| check_
[[n_]] != ilooka_
)
342 /* Reduce or error. */
361 /* Shift the lookahead token. */
362 YYDPRINTF ((stderr
, "Shifting token %d (%s), ", looka_
, name_
[[ilooka_]]));
364 /* Discard the token being shifted unless it is eof. */
368 semantic_stack_
.push (value
);
369 location_stack_
.push (location
);
371 /* Count tokens shifted since error; after three, turn off error
379 /* Default action. */
381 n_
= defact_
[[state_]];
391 yyval
= semantic_stack_
[[1 - len_
]];
392 yyloc
= location_stack_
[[1 - len_
]];
396 yyval
= semantic_stack_
[[0]];
397 yyloc
= location_stack_
[[0]];
403 YYFPRINTF (stderr
, "Reducing via rule %d (line %d), ", n_
- 1, rline_
[[n_]]);
404 for (unsigned i
= prhs_
[[n_]];
406 YYFPRINTF (stderr
, "%s ", name_
[[rhs_
[i
]]]);
407 YYFPRINTF (stderr
, "-> %s\n", name_
[[r1_
[n_
]]]);
413 Slice
< LocationType
, LocationStack
> slice (location_stack_
, len_
);
414 YYLLOC_DEFAULT (yyloc
, slice
, len_
);
418 SemanticStack
& yyvsp (semantic_stack_
);
419 LocationStack
& yylsp (location_stack_
);
427 state_stack_
.pop (len_
);
428 semantic_stack_
.pop (len_
);
429 location_stack_
.pop (len_
);
434 YYFPRINTF (stderr
, "state stack now");
435 for (StateStack::ConstIterator i
= state_stack_
.begin ();
436 i
!= state_stack_
.end (); ++i
)
437 YYFPRINTF (stderr
, " %d", *i
);
438 YYFPRINTF (stderr
, "\n");
442 semantic_stack_
.push (yyval
);
443 location_stack_
.push (yyloc
);
445 /* Shift the result of the reduction. */
447 state_
= pgoto_
[[n_
- ntokens_
]] + state_stack_
[[0]];
448 if (state_
>= 0 && state_
<= last_
&& check_
[[state_]] == state_stack_
[[0]])
449 state_
= table_
[[state_]];
451 state_
= defgoto_
[[n_
- ntokens_
]];
454 /* Report and recover from errors. This is very incomplete. */
456 /* If not already recovering from an error, report this error. */
462 n_
= pact_
[[state_]];
463 if (n_
> flag_
&& n_
< last_
)
465 message
= "parse error, unexpected ";
466 message
+= name_
[[ilooka_]];
469 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
470 if (check_
[[x
+ n_
]] == x
)
475 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
476 if (check_
[[x
+ n_
]] == x
)
478 message
+= (!count
++) ? ", expecting " : " or ";
479 message
+= name_
[[x]];
486 message
= "parse error";
491 /* Error raised explicitly by an action. */
495 /* If just tried and failed to reuse lookahead token after an
496 error, discard it. */
498 /* Return failure if at end of input. */
501 YYDPRINTF ((stderr
, "Discarding token %d (%s).\n", looka_
, name_
[[ilooka_]]));
505 /* Else will try to reuse lookahead token after shifting the error
511 /* Pop the current state because it cannot handle the error token. */
514 if (!state_stack_
.height ())
516 state_
= (state_stack_
.pop (), state_stack_
[[0]]);
517 semantic_stack_
.pop ();
518 location_stack_
.pop ();;
523 YYFPRINTF (stderr
, "Error: state stack now");
524 for (StateStack::ConstIterator i
= state_stack_
.begin ();
525 i
!= state_stack_
.end (); ++i
)
526 YYFPRINTF (stderr
, " %d", *i
);
527 YYFPRINTF (stderr
, "\n");
532 n_
= pact_
[[state_]];
537 if (n_
< 0 || n_
> last_
|| check_
[[n_]] != terror_
)
554 YYDPRINTF ((stderr
, "Shifting error token, "));
556 semantic_stack_
.push (value
);
557 location_stack_
.push (location
);
575 looka_
= yylex (&value
, &location
);
577 looka_
= yylex (&value
);
581 /* YYPACT[[STATE-NUM]] -- Index in YYTABLE of the portion describing
584 yy::b4_name::pact_
[[]] =
589 /* YYDEFACT[[S]] -- default rule to reduce with in state S when YYTABLE
590 doesn't specify something else to do. Zero means the default is an
593 yy::b4_name::defact_
[[]] =
598 /* YYPGOTO[[NTERM-NUM]]. */
600 yy::b4_name::pgoto_
[[]] =
605 /* YYDEFGOTO[[NTERM-NUM]]. */
607 yy::b4_name::defgoto_
[[]] =
612 /* YYTABLE[[YYPACT[STATE-NUM]]]. What to do in state STATE-NUM. If
613 positive, shift that token. If negative, reduce the rule which
614 number is the opposite. If zero, do what YYDEFACT says. */
616 yy::b4_name::table_
[[]] =
623 yy::b4_name::check_
[[]] =
628 /* YYR1[[YYN]] -- Symbol number of symbol that rule YYN derives. */
630 yy::b4_name::r1_
[[]] =
635 /* YYR2[[YYN]] -- Number of symbols composing right hand side of rule YYN. */
637 yy::b4_name::r2_
[[]] =
642 #if YYDEBUG || YYERROR_VERBOSE
643 /* YYTNAME[[SYMBOL-NUM]] -- String name of the symbol SYMBOL-NUM.
644 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
646 const yy::b4_name::name_
[[]] =
653 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
655 yy::b4_name::rhs_
[[]] =
660 /* YYPRHS[[YYN]] -- Index of the first RHS symbol of rule number YYN in
663 yy::b4_name::prhs_
[[]] =
668 /* YYRLINE[[YYN]] -- source line where rule number YYN was defined. */
670 yy::b4_name::rline_
[[]] =
676 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
678 yy::b4_name::translate_ (int token
)
686 return ((unsigned)(token
) <= maxtok_
? translate_
[[token]] : nsym_
);
689 const int yy::b4_name::eof_
= 0;
690 const int yy::b4_name::last_
= b4_last
;
691 const int yy::b4_name::flag_
= b4_flag
;
692 const int yy::b4_name::nnts_
= b4_nnts
;
693 const int yy::b4_name::nsym_
= b4_nsym
;
694 const int yy::b4_name::empty_
= -2;
695 const int yy::b4_name::final_
= b4_final
;
696 const int yy::b4_name::terror_
= 1;
697 const int yy::b4_name::errcode_
= 256;
698 const int yy::b4_name::ntokens_
= b4_ntokens
;
699 const int yy::b4_name::initdepth_
= b4_initdepth
;
701 const unsigned yy::b4_name::maxtok_
= b4_maxtok
;
708 #ifndef BISON_STACK_HH
709 # define BISON_STACK_HH
715 template < class T
, class S
= std::vector
< T
> >
720 typedef typename
S::iterator Iterator
;
721 typedef typename
S::const_iterator ConstIterator
;
727 Stack (unsigned n
) : seq_ (n
)
733 operator [[]] (int index
)
735 return seq_
[[height () - 1 + index
]];
740 operator [[]] (int index
) const
742 return seq_
[[height () - 1 + index
]];
774 inline ConstIterator
begin () const { return seq_
.begin (); }
775 inline ConstIterator
end () const { return seq_
.end (); }
782 template < class T
, class S
= Stack
< T
> >
787 Slice (const S
& stack
,
788 unsigned range
) : stack_ (stack
),
795 operator [[]] (unsigned index
) const
797 return stack_
[[index
- range_
]];
807 #endif // not BISON_STACK_HH
809 #output "location.hh"
812 #ifndef BISON_LOCATION_HH
813 # define BISON_LOCATION_HH
830 #endif // not BISON_LOCATION_HH