5 # Return the smallest signed int type able to handle the number MAX.
6 m4_define([b4_sint_type
],
7 [m4_if(m4_eval([$
1 <= 127]), [1], [signed char],
8 m4_eval([$
1 <= 32767]), [1], [signed short],
9 m4_eval([$
1 <= 2147483647]), [1], [signed int],
10 [m4_fatal([no
signed int type
for $
1])])])
15 # Return the smallest unsigned int type able to handle the number MAX.
16 m4_define([b4_uint_type
],
17 [m4_if(m4_eval([$
1 <= 255]), [1], [unsigned char],
18 m4_eval([$
1 <= 65535]), [1], [unsigned short],
19 m4_eval([$
1 <= 4294967295]), [1], [unsigned int],
20 [m4_fatal([no
unsigned int type
for $
1])])])
23 # b4_token_defines(TOKEN-NAME, TOKEN-NUMBER)
24 # ------------------------------------------
25 # Output the definition of this token as #define.
26 m4_define([b4_token_define
],
31 # b4_token_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
32 # -------------------------------------------------------
33 # Output the definition of the tokens as #define.
34 m4_define([b4_token_defines
],
35 [m4_map([b4_token_define
], [$@
])])
37 m4_define_default([b4_input_suffix
], [.y
])
39 m4_define_default([b4_output_parser_suffix
],
40 [m4_translit(b4_input_suffix
, [yY
], [cC
])])
42 m4_define_default([b4_output_parser_name
],
43 [b4_output_prefix
[]b4_output_infix
[]b4_output_parser_suffix
[]])
46 m4_define_default([b4_output_header_suffix
],
47 [m4_translit(b4_input_suffix
, [yY
], [hH
])])
49 m4_define_default([b4_output_header_name
],
50 [b4_output_prefix
[]b4_output_infix
[]b4_output_header_suffix
[]])
52 m4_define_default([b4_header_guard
],
53 [m4_bpatsubst(m4_toupper([BISON_
]b4_output_header_name
),
54 [[^ABCDEFGHIJKLMNOPQRSTUVWXYZ
]], [_
])])
56 m4_define([b4_inherit
],
68 m4_define([b4_constructor
],
74 m4_define([b4_copyright
],
76 /* A Bison parser, made from b4_filename,
77 by GNU bison b4_version. */
79 /* Skeleton output parser for bison,
80 Copyright 2002 Free Software Foundation, Inc.
82 This program is free software; you can redistribute it and/or modify
83 it under the terms of the GNU General Public License as published by
84 the Free Software Foundation; either version 2, or (at your option)
87 This program is distributed in the hope that it will be useful,
88 but WITHOUT ANY WARRANTY; without even the implied warranty of
89 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
90 GNU General Public License for more details.
92 You should have received a copy of the GNU General Public License
93 along with this program; if not, write to the Free Software
94 Foundation, Inc., 59 Temple Place - Suite 330,
95 Boston, MA 02111-1307, USA. */
97 /* As a special exception, when this file is copied by Bison into a
98 Bison output file, you may use that output file without restriction.
99 This special exception was added by the Free Software Foundation
100 in version 1.24 of Bison. */])
103 #output "b4_output_header_name"
105 #ifndef b4_header_guard
106 # define b4_header_guard
109 #include "location.hh"
113 /* Using locations. */
114 #define YYLSP_NEEDED b4_locations_flag
119 b4_token_defines(b4_tokens
)
121 /* Enabling traces. */
123 # define YYDEBUG b4_debug
126 /* Enabling verbose error message. */
127 #ifndef YYERROR_VERBOSE
128 # define YYERROR_VERBOSE b4_error_verbose
132 m4_ifdef([b4_stype_line
],
133 [#line b4_stype_line "b4_filename"
137 # define YYSTYPE yystype
140 #ifndef YYLLOC_DEFAULT
141 # define YYLLOC_DEFAULT(Current, Rhs, N) \
142 Current.last_line = Rhs[[N]].last_line; \
143 Current.last_column = Rhs[[N]].last_column;
146 m4_if(b4_locations_flag
, [0], [],
148 typedef struct yyltype
155 # define YYLTYPE yyltype
162 template < typename P
>
168 struct Traits
< b4_name
>
170 typedef typedef b4_uint_type(b4_token_number_max
) TokenNumberType
;
171 typedef typedef b4_sint_type(b4_item_number_max
) RhsNumberType
;
172 typedef int StateType
;
173 typedef yystype SemanticType
;
174 typedef b4_ltype LocationType
;
180 class b4_name b4_inherit
184 typedef Traits
< b4_name
>::TokenNumberType TokenNumberType
;
185 typedef Traits
< b4_name
>::RhsNumberType TokenNumberType
;
186 typedef Traits
< b4_name
>::StateType StateType
;
187 typedef Traits
< b4_name
>::SemanticType SemanticType
;
188 typedef Traits
< b4_name
>::LocationType LocationType
;
190 typedef Stack
< StateType
> StateStack
;
191 typedef Stack
< SemanticType
> SemanticStack
;
192 typedef Stack
< LocationType
> LocationStack
;
196 LocationType initlocation
[]b4_param
) :
197 b4_constructor
[]debug_ (debug
),
198 initlocation_ (initlocation
)
200 b4_name (bool debug
[]b4_param
) :
201 b4_constructor
[]debug_ (debug
)
210 virtual int parse ();
214 virtual void lex_ ();
215 virtual void error_ ();
216 virtual void print_ ();
219 StateStack state_stack_
;
220 SemanticStack semantic_stack_
;
221 LocationStack location_stack_
;
224 static const short pact_
[[]];
225 static const short defact_
[[]];
226 static const short pgoto_
[[]];
227 static const short defgoto_
[[]];
228 static const short table_
[[]];
229 static const short check_
[[]];
230 static const short r1_
[[]];
231 static const short r2_
[[]];
233 #if YYDEBUG || YYERROR_VERBOSE
234 static const char* const name_
[[]];
237 /* More tables, for debugging. */
239 static const short rhs_
[[]];
240 static const short prhs_
[[]];
241 static const short rline_
[[]];
244 /* Even more tables. */
245 static inline TokenNumberType
translate_ (int token
);
248 static const int eof_
;
249 static const int last_
;
250 static const int flag_
;
251 static const int nnts_
;
252 static const int nsym_
;
253 static const int empty_
;
254 static const int final_
;
255 static const int terror_
;
256 static const int errcode_
;
257 static const int ntokens_
;
258 static const int initdepth_
;
259 static const unsigned maxtok_
;
267 /* Lookahead and lookahead in internal form. */
274 /* Semantic value and location of lookahead token. */
276 LocationType location
;
282 /* Initial location. */
283 LocationType initlocation_
;
287 #endif /* not b4_header_guard */
289 #output "b4_output_prefix[]b4_output_infix[].cc"
292 #include "b4_output_header_name"
294 /* Enable debugging if requested. */
297 # define YYFPRINTF std::fprintf
298 # define YYDPRINTF(Args) \
304 # define YYDPRINTF(Args)
305 #endif /* !YYDEBUG */
308 yy::b4_name::parse ()
313 /* Initialize stack. */
314 state_stack_
= StateStack (0);
315 semantic_stack_
= SemanticStack (1);
316 location_stack_
= LocationStack (1);
318 /* Reserve initial space. The C parser needed that, but is it really
320 state_stack_
.reserve (initdepth_
);
321 semantic_stack_
.reserve (initdepth_
);
322 location_stack_
.reserve (initdepth_
);
328 location
= initlocation_
;
330 YYDPRINTF ((stderr
, "Starting parse\n"));
334 state_stack_
.push (state_
);
335 YYDPRINTF ((stderr
, "Entering state %d\n", state_
));
341 /* Try to take a decision without lookahead. */
342 n_
= pact_
[[state_]];
346 /* Read a lookahead token. */
347 if (looka_
== empty_
)
349 YYDPRINTF ((stderr
, "Reading a token: "));
353 /* Convert token to internal form. */
358 YYDPRINTF ((stderr
, "Now at end of input.\n"));
362 ilooka_
= translate_ (looka_
);
366 YYFPRINTF (stderr
, "Next token is %d (%s", looka_
, name_
[[ilooka_]]);
368 YYFPRINTF (stderr
, ")\n");
374 if (n_
< 0 || n_
> last_
|| check_
[[n_]] != ilooka_
)
377 /* Reduce or error. */
396 /* Shift the lookahead token. */
397 YYDPRINTF ((stderr
, "Shifting token %d (%s), ", looka_
, name_
[[ilooka_]]));
399 /* Discard the token being shifted unless it is eof. */
403 semantic_stack_
.push (value
);
404 location_stack_
.push (location
);
406 /* Count tokens shifted since error; after three, turn off error
414 /* Default action. */
416 n_
= defact_
[[state_]];
426 yyval
= semantic_stack_
[[1 - len_
]];
427 yyloc
= location_stack_
[[1 - len_
]];
431 yyval
= semantic_stack_
[[0]];
432 yyloc
= location_stack_
[[0]];
438 YYFPRINTF (stderr
, "Reducing via rule %d (line %d), ", n_
- 1, rline_
[[n_]]);
439 for (unsigned i
= prhs_
[[n_]];
441 YYFPRINTF (stderr
, "%s ", name_
[[rhs_
[i
]]]);
442 YYFPRINTF (stderr
, "-> %s\n", name_
[[r1_
[n_
]]]);
448 Slice
< LocationType
, LocationStack
> slice (location_stack_
, len_
);
449 YYLLOC_DEFAULT (yyloc
, slice
, len_
);
453 SemanticStack
& yyvsp (semantic_stack_
);
454 LocationStack
& yylsp (location_stack_
);
462 state_stack_
.pop (len_
);
463 semantic_stack_
.pop (len_
);
464 location_stack_
.pop (len_
);
469 YYFPRINTF (stderr
, "state stack now");
470 for (StateStack::ConstIterator i
= state_stack_
.begin ();
471 i
!= state_stack_
.end (); ++i
)
472 YYFPRINTF (stderr
, " %d", *i
);
473 YYFPRINTF (stderr
, "\n");
477 semantic_stack_
.push (yyval
);
478 location_stack_
.push (yyloc
);
480 /* Shift the result of the reduction. */
482 state_
= pgoto_
[[n_
- ntokens_
]] + state_stack_
[[0]];
483 if (state_
>= 0 && state_
<= last_
&& check_
[[state_]] == state_stack_
[[0]])
484 state_
= table_
[[state_]];
486 state_
= defgoto_
[[n_
- ntokens_
]];
489 /* Report and recover from errors. This is very incomplete. */
491 /* If not already recovering from an error, report this error. */
497 n_
= pact_
[[state_]];
498 if (n_
> flag_
&& n_
< last_
)
500 message
= "parse error, unexpected ";
501 message
+= name_
[[ilooka_]];
504 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
505 if (check_
[[x
+ n_
]] == x
)
510 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
511 if (check_
[[x
+ n_
]] == x
)
513 message
+= (!count
++) ? ", expecting " : " or ";
514 message
+= name_
[[x]];
521 message
= "parse error";
526 /* Error raised explicitly by an action. */
530 /* If just tried and failed to reuse lookahead token after an
531 error, discard it. */
533 /* Return failure if at end of input. */
536 YYDPRINTF ((stderr
, "Discarding token %d (%s).\n", looka_
, name_
[[ilooka_]]));
540 /* Else will try to reuse lookahead token after shifting the error
546 /* Pop the current state because it cannot handle the error token. */
549 if (!state_stack_
.height ())
551 state_
= (state_stack_
.pop (), state_stack_
[[0]]);
552 semantic_stack_
.pop ();
553 location_stack_
.pop ();;
558 YYFPRINTF (stderr
, "Error: state stack now");
559 for (StateStack::ConstIterator i
= state_stack_
.begin ();
560 i
!= state_stack_
.end (); ++i
)
561 YYFPRINTF (stderr
, " %d", *i
);
562 YYFPRINTF (stderr
, "\n");
567 n_
= pact_
[[state_]];
572 if (n_
< 0 || n_
> last_
|| check_
[[n_]] != terror_
)
589 YYDPRINTF ((stderr
, "Shifting error token, "));
591 semantic_stack_
.push (value
);
592 location_stack_
.push (location
);
610 looka_
= yylex (&value
, &location
);
612 looka_
= yylex (&value
);
616 /* YYPACT[[STATE-NUM]] -- Index in YYTABLE of the portion describing
619 yy::b4_name::pact_
[[]] =
624 /* YYDEFACT[[S]] -- default rule to reduce with in state S when YYTABLE
625 doesn't specify something else to do. Zero means the default is an
628 yy::b4_name::defact_
[[]] =
633 /* YYPGOTO[[NTERM-NUM]]. */
635 yy::b4_name::pgoto_
[[]] =
640 /* YYDEFGOTO[[NTERM-NUM]]. */
642 yy::b4_name::defgoto_
[[]] =
647 /* YYTABLE[[YYPACT[STATE-NUM]]]. What to do in state STATE-NUM. If
648 positive, shift that token. If negative, reduce the rule which
649 number is the opposite. If zero, do what YYDEFACT says. */
651 yy::b4_name::table_
[[]] =
658 yy::b4_name::check_
[[]] =
663 /* YYR1[[YYN]] -- Symbol number of symbol that rule YYN derives. */
665 yy::b4_name::r1_
[[]] =
670 /* YYR2[[YYN]] -- Number of symbols composing right hand side of rule YYN. */
672 yy::b4_name::r2_
[[]] =
677 #if YYDEBUG || YYERROR_VERBOSE
678 /* YYTNAME[[SYMBOL-NUM]] -- String name of the symbol SYMBOL-NUM.
679 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
681 const yy::b4_name::name_
[[]] =
688 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
690 yy::b4_name::rhs_
[[]] =
695 /* YYPRHS[[YYN]] -- Index of the first RHS symbol of rule number YYN in
698 yy::b4_name::prhs_
[[]] =
703 /* YYRLINE[[YYN]] -- source line where rule number YYN was defined. */
705 yy::b4_name::rline_
[[]] =
711 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
713 yy::b4_name::translate_ (int token
)
716 const TokenNumberType
721 return (unsigned)(token
) <= maxtok_
? translate_
[[token]] : nsym_
;
724 const int yy::b4_name::eof_
= 0;
725 const int yy::b4_name::last_
= b4_last
;
726 const int yy::b4_name::flag_
= b4_flag
;
727 const int yy::b4_name::nnts_
= b4_nnts
;
728 const int yy::b4_name::nsym_
= b4_nsym
;
729 const int yy::b4_name::empty_
= -2;
730 const int yy::b4_name::final_
= b4_final
;
731 const int yy::b4_name::terror_
= 1;
732 const int yy::b4_name::errcode_
= 256;
733 const int yy::b4_name::ntokens_
= b4_ntokens
;
734 const int yy::b4_name::initdepth_
= b4_initdepth
;
736 const unsigned yy::b4_name::maxtok_
= b4_maxtok
;
743 #ifndef BISON_STACK_HH
744 # define BISON_STACK_HH
750 template < class T
, class S
= std::vector
< T
> >
755 typedef typename
S::iterator Iterator
;
756 typedef typename
S::const_iterator ConstIterator
;
762 Stack (unsigned n
) : seq_ (n
)
768 operator [[]] (int index
)
770 return seq_
[[height () - 1 + index
]];
775 operator [[]] (int index
) const
777 return seq_
[[height () - 1 + index
]];
809 inline ConstIterator
begin () const { return seq_
.begin (); }
810 inline ConstIterator
end () const { return seq_
.end (); }
817 template < class T
, class S
= Stack
< T
> >
822 Slice (const S
& stack
,
823 unsigned range
) : stack_ (stack
),
830 operator [[]] (unsigned index
) const
832 return stack_
[[index
- range_
]];
842 #endif // not BISON_STACK_HH
844 #output "location.hh"
847 #ifndef BISON_LOCATION_HH
848 # define BISON_LOCATION_HH
865 #endif // not BISON_LOCATION_HH