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 #ifndef YYLLOC_DEFAULT
92 # define YYLLOC_DEFAULT(Current, Rhs, N) \
93 Current.last_line = Rhs[[N]].last_line; \
94 Current.last_column = Rhs[[N]].last_column;
97 m4_if(b4_locations_flag
, [0], [],
99 typedef struct yyltype
106 # define YYLTYPE yyltype
113 template < typename P
>
119 struct Traits
< b4_name
>
121 typedef int StateType
;
122 typedef yystype SemanticType
;
123 typedef b4_ltype LocationType
;
133 typedef Traits
< b4_name
>::StateType StateType
;
134 typedef Traits
< b4_name
>::SemanticType SemanticType
;
135 typedef Traits
< b4_name
>::LocationType LocationType
;
137 typedef Stack
< StateType
> StateStack
;
138 typedef Stack
< SemanticType
> SemanticStack
;
139 typedef Stack
< LocationType
> LocationStack
;
143 LocationType initlocation
) : debug_ (debug
),
144 initlocation_ (initlocation
)
146 b4_name (bool debug
) : debug_ (debug
)
155 virtual int parse ();
159 virtual void lex_ ();
160 virtual void error_ ();
161 virtual void print_ ();
164 StateStack state_stack_
;
165 SemanticStack semantic_stack_
;
166 LocationStack location_stack_
;
169 static const short pact_
[[]];
170 static const short defact_
[[]];
171 static const short pgoto_
[[]];
172 static const short defgoto_
[[]];
173 static const short table_
[[]];
174 static const short check_
[[]];
175 static const short r1_
[[]];
176 static const short r2_
[[]];
178 #if YYDEBUG || YYERROR_VERBOSE
179 static const char* const name_
[[]];
182 /* More tables, for debugging. */
184 static const short rhs_
[[]];
185 static const short prhs_
[[]];
186 static const short rline_
[[]];
189 /* Even more tables. */
190 static inline char translate_ (int token
);
193 static const int eof_
;
194 static const int last_
;
195 static const int flag_
;
196 static const int nnts_
;
197 static const int nsym_
;
198 static const int empty_
;
199 static const int final_
;
200 static const int terror_
;
201 static const int errcode_
;
202 static const int ntokens_
;
203 static const int initdepth_
;
204 static const unsigned maxtok_
;
212 /* Lookahead and lookahead in internal form. */
219 /* Semantic value and location of lookahead token. */
221 LocationType location
;
227 /* Initial location. */
228 LocationType initlocation_
;
232 #endif /* not b4_header_guard */
234 #output "b4_output_prefix[]b4_output_infix[].cc"
237 #include "b4_output_header_name"
239 /* Enable debugging if requested. */
242 # define YYFPRINTF std::fprintf
243 # define YYDPRINTF(Args) \
249 # define YYDPRINTF(Args)
250 #endif /* !YYDEBUG */
253 yy::b4_name::parse ()
258 /* Initialize stack. */
259 state_stack_
= StateStack (0);
260 semantic_stack_
= SemanticStack (1);
261 location_stack_
= LocationStack (1);
263 /* Reserve initial space. The C parser needed that, but is it really
265 state_stack_
.reserve (initdepth_
);
266 semantic_stack_
.reserve (initdepth_
);
267 location_stack_
.reserve (initdepth_
);
273 location
= initlocation_
;
275 YYDPRINTF ((stderr
, "Starting parse\n"));
279 state_stack_
.push (state_
);
280 YYDPRINTF ((stderr
, "Entering state %d\n", state_
));
286 /* Try to take a decision without lookahead. */
287 n_
= pact_
[[state_]];
291 /* Read a lookahead token. */
292 if (looka_
== empty_
)
294 YYDPRINTF ((stderr
, "Reading a token: "));
298 /* Convert token to internal form. */
303 YYDPRINTF ((stderr
, "Now at end of input.\n"));
307 ilooka_
= translate_ (looka_
);
311 YYFPRINTF (stderr
, "Next token is %d (%s", looka_
, name_
[[ilooka_]]);
313 YYFPRINTF (stderr
, ")\n");
319 if (n_
< 0 || n_
> last_
|| check_
[[n_]] != ilooka_
)
322 /* Reduce or error. */
341 /* Shift the lookahead token. */
342 YYDPRINTF ((stderr
, "Shifting token %d (%s), ", looka_
, name_
[[ilooka_]]));
344 /* Discard the token being shifted unless it is eof. */
348 semantic_stack_
.push (value
);
349 location_stack_
.push (location
);
351 /* Count tokens shifted since error; after three, turn off error
359 /* Default action. */
361 n_
= defact_
[[state_]];
371 yyval
= semantic_stack_
[[1 - len_
]];
372 yyloc
= location_stack_
[[1 - len_
]];
376 yyval
= semantic_stack_
[[0]];
377 yyloc
= location_stack_
[[0]];
383 YYFPRINTF (stderr
, "Reducing via rule %d (line %d), ", n_
- 1, rline_
[[n_]]);
384 for (unsigned i
= prhs_
[[n_]];
386 YYFPRINTF (stderr
, "%s ", name_
[[rhs_
[i
]]]);
387 YYFPRINTF (stderr
, "-> %s\n", name_
[[r1_
[n_
]]]);
393 Slice
< LocationType
, LocationStack
> slice (location_stack_
, len_
);
394 YYLLOC_DEFAULT (yyloc
, slice
, len_
);
398 SemanticStack
& yyvsp (semantic_stack_
);
399 LocationStack
& yylsp (location_stack_
);
407 state_stack_
.pop (len_
);
408 semantic_stack_
.pop (len_
);
409 location_stack_
.pop (len_
);
414 YYFPRINTF (stderr
, "state stack now");
415 for (StateStack::ConstIterator i
= state_stack_
.begin ();
416 i
!= state_stack_
.end (); ++i
)
417 YYFPRINTF (stderr
, " %d", *i
);
418 YYFPRINTF (stderr
, "\n");
422 semantic_stack_
.push (yyval
);
423 location_stack_
.push (yyloc
);
425 /* Shift the result of the reduction. */
427 state_
= pgoto_
[[n_
- ntokens_
]] + state_stack_
[[0]];
428 if (state_
>= 0 && state_
<= last_
&& check_
[[state_]] == state_stack_
[[0]])
429 state_
= table_
[[state_]];
431 state_
= defgoto_
[[n_
- ntokens_
]];
434 /* Report and recover from errors. This is very incomplete. */
436 /* If not already recovering from an error, report this error. */
442 n_
= pact_
[[state_]];
443 if (n_
> flag_
&& n_
< last_
)
445 message
= "parse error, unexpected ";
446 message
+= name_
[[ilooka_]];
449 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
450 if (check_
[[x
+ n_
]] == x
)
455 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
456 if (check_
[[x
+ n_
]] == x
)
458 message
+= (!count
++) ? ", expecting " : " or ";
459 message
+= name_
[[x]];
466 message
= "parse error";
471 /* Error raised explicitly by an action. */
475 /* If just tried and failed to reuse lookahead token after an
476 error, discard it. */
478 /* Return failure if at end of input. */
481 YYDPRINTF ((stderr
, "Discarding token %d (%s).\n", looka_
, name_
[[ilooka_]]));
485 /* Else will try to reuse lookahead token after shifting the error
491 /* Pop the current state because it cannot handle the error token. */
494 if (!state_stack_
.height ())
496 state_
= (state_stack_
.pop (), state_stack_
[[0]]);
497 semantic_stack_
.pop ();
498 location_stack_
.pop ();;
503 YYFPRINTF (stderr
, "Error: state stack now");
504 for (StateStack::ConstIterator i
= state_stack_
.begin ();
505 i
!= state_stack_
.end (); ++i
)
506 YYFPRINTF (stderr
, " %d", *i
);
507 YYFPRINTF (stderr
, "\n");
512 n_
= pact_
[[state_]];
517 if (n_
< 0 || n_
> last_
|| check_
[[n_]] != terror_
)
534 YYDPRINTF ((stderr
, "Shifting error token, "));
536 semantic_stack_
.push (value
);
537 location_stack_
.push (location
);
555 looka_
= yylex (&value
, &location
);
557 looka_
= yylex (&value
);
561 /* YYPACT[[STATE-NUM]] -- Index in YYTABLE of the portion describing
564 yy::b4_name::pact_
[[]] =
569 /* YYDEFACT[[S]] -- default rule to reduce with in state S when YYTABLE
570 doesn't specify something else to do. Zero means the default is an
573 yy::b4_name::defact_
[[]] =
578 /* YYPGOTO[[NTERM-NUM]]. */
580 yy::b4_name::pgoto_
[[]] =
585 /* YYDEFGOTO[[NTERM-NUM]]. */
587 yy::b4_name::defgoto_
[[]] =
592 /* YYTABLE[[YYPACT[STATE-NUM]]]. What to do in state STATE-NUM. If
593 positive, shift that token. If negative, reduce the rule which
594 number is the opposite. If zero, do what YYDEFACT says. */
596 yy::b4_name::table_
[[]] =
603 yy::b4_name::check_
[[]] =
608 /* YYR1[[YYN]] -- Symbol number of symbol that rule YYN derives. */
610 yy::b4_name::r1_
[[]] =
615 /* YYR2[[YYN]] -- Number of symbols composing right hand side of rule YYN. */
617 yy::b4_name::r2_
[[]] =
622 #if YYDEBUG || YYERROR_VERBOSE
623 /* YYTNAME[[SYMBOL-NUM]] -- String name of the symbol SYMBOL-NUM.
624 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
626 const yy::b4_name::name_
[[]] =
633 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
635 yy::b4_name::rhs_
[[]] =
640 /* YYPRHS[[YYN]] -- Index of the first RHS symbol of rule number YYN in
643 yy::b4_name::prhs_
[[]] =
648 /* YYRLINE[[YYN]] -- source line where rule number YYN was defined. */
650 yy::b4_name::rline_
[[]] =
656 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
658 yy::b4_name::translate_ (int token
)
666 return ((unsigned)(token
) <= maxtok_
? translate_
[[token]] : nsym_
);
669 const int yy::b4_name::eof_
= 0;
670 const int yy::b4_name::last_
= b4_last
;
671 const int yy::b4_name::flag_
= b4_flag
;
672 const int yy::b4_name::nnts_
= b4_nnts
;
673 const int yy::b4_name::nsym_
= b4_nsym
;
674 const int yy::b4_name::empty_
= -2;
675 const int yy::b4_name::final_
= b4_final
;
676 const int yy::b4_name::terror_
= 1;
677 const int yy::b4_name::errcode_
= 256;
678 const int yy::b4_name::ntokens_
= b4_ntokens
;
679 const int yy::b4_name::initdepth_
= b4_initdepth
;
681 const unsigned yy::b4_name::maxtok_
= b4_maxtok
;
688 #ifndef BISON_STACK_HH
689 # define BISON_STACK_HH
695 template < class T
, class S
= std::vector
< T
> >
700 typedef typename
S::iterator Iterator
;
701 typedef typename
S::const_iterator ConstIterator
;
707 Stack (unsigned n
) : seq_ (n
)
713 operator [[]] (int index
)
715 return seq_
[[height () - 1 + index
]];
720 operator [[]] (int index
) const
722 return seq_
[[height () - 1 + index
]];
754 inline ConstIterator
begin () const { return seq_
.begin (); }
755 inline ConstIterator
end () const { return seq_
.end (); }
762 template < class T
, class S
= Stack
< T
> >
767 Slice (const S
& stack
,
768 unsigned range
) : stack_ (stack
),
775 operator [[]] (unsigned index
) const
777 return stack_
[[index
- range_
]];
787 #endif // not BISON_STACK_HH
789 #output "location.hh"
792 #ifndef BISON_LOCATION_HH
793 # define BISON_LOCATION_HH
810 #endif // not BISON_LOCATION_HH