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
116 /* Copy the first part of user declarations. */
120 b4_token_defines(b4_tokens
)
122 /* Enabling traces. */
124 # define YYDEBUG b4_debug
127 /* Enabling verbose error message. */
128 #ifndef YYERROR_VERBOSE
129 # define YYERROR_VERBOSE b4_error_verbose
133 m4_ifdef([b4_stype_line
],
134 [#line b4_stype_line "b4_filename"
138 # define YYSTYPE yystype
141 /* Copy the second part of user declarations. */
144 #line __oline__ "__ofile__"
145 #ifndef YYLLOC_DEFAULT
146 # define YYLLOC_DEFAULT(Current, Rhs, N) \
147 Current.last_line = Rhs[[N]].last_line; \
148 Current.last_column = Rhs[[N]].last_column;
151 m4_if(b4_locations_flag
, [0], [],
153 typedef struct yyltype
160 # define YYLTYPE yyltype
167 template < typename P
>
173 struct Traits
< b4_name
>
175 typedef b4_uint_type(b4_token_number_max
) TokenNumberType
;
176 typedef b4_sint_type(b4_rhs_number_max
) RhsNumberType
;
177 typedef int StateType
;
178 typedef yystype SemanticType
;
179 typedef b4_ltype LocationType
;
185 class b4_name b4_inherit
189 typedef Traits
< b4_name
>::TokenNumberType TokenNumberType
;
190 typedef Traits
< b4_name
>::RhsNumberType RhsNumberType
;
191 typedef Traits
< b4_name
>::StateType StateType
;
192 typedef Traits
< b4_name
>::SemanticType SemanticType
;
193 typedef Traits
< b4_name
>::LocationType LocationType
;
195 typedef Stack
< StateType
> StateStack
;
196 typedef Stack
< SemanticType
> SemanticStack
;
197 typedef Stack
< LocationType
> LocationStack
;
201 LocationType initlocation
[]b4_param
) :
202 b4_constructor
[]debug_ (debug
),
203 initlocation_ (initlocation
)
205 b4_name (bool debug
[]b4_param
) :
206 b4_constructor
[]debug_ (debug
)
215 virtual int parse ();
219 virtual void lex_ ();
220 virtual void error_ ();
221 virtual void print_ ();
224 StateStack state_stack_
;
225 SemanticStack semantic_stack_
;
226 LocationStack location_stack_
;
229 static const short pact_
[[]];
230 static const short defact_
[[]];
231 static const short pgoto_
[[]];
232 static const short defgoto_
[[]];
233 static const short table_
[[]];
234 static const short check_
[[]];
235 static const TokenNumberType r1_
[[]];
236 static const short r2_
[[]];
238 #if YYDEBUG || YYERROR_VERBOSE
239 static const char* const name_
[[]];
242 /* More tables, for debugging. */
244 static const RhsNumberType rhs_
[[]];
245 static const short prhs_
[[]];
246 static const short rline_
[[]];
249 /* Even more tables. */
250 static inline TokenNumberType
translate_ (int token
);
253 static const int eof_
;
254 static const int last_
;
255 static const int flag_
;
256 static const int nnts_
;
257 static const int nsym_
;
258 static const int empty_
;
259 static const int final_
;
260 static const int terror_
;
261 static const int errcode_
;
262 static const int ntokens_
;
263 static const int initdepth_
;
264 static const unsigned user_token_number_max_
;
265 static const TokenNumberType undef_token_
;
273 /* Lookahead and lookahead in internal form. */
280 /* Semantic value and location of lookahead token. */
282 LocationType location
;
288 /* Initial location. */
289 LocationType initlocation_
;
293 #endif /* not b4_header_guard */
295 #output "b4_output_prefix[]b4_output_infix[].cc"
298 #include "b4_output_header_name"
300 /* Enable debugging if requested. */
303 # define YYFPRINTF std::fprintf
304 # define YYDPRINTF(Args) \
310 # define YYDPRINTF(Args)
311 #endif /* !YYDEBUG */
314 yy::b4_name::parse ()
319 /* Initialize stack. */
320 state_stack_
= StateStack (0);
321 semantic_stack_
= SemanticStack (1);
322 location_stack_
= LocationStack (1);
324 /* Reserve initial space. The C parser needed that, but is it really
326 state_stack_
.reserve (initdepth_
);
327 semantic_stack_
.reserve (initdepth_
);
328 location_stack_
.reserve (initdepth_
);
334 location
= initlocation_
;
336 YYDPRINTF ((stderr
, "Starting parse\n"));
340 state_stack_
.push (state_
);
341 YYDPRINTF ((stderr
, "Entering state %d\n", state_
));
347 /* Try to take a decision without lookahead. */
348 n_
= pact_
[[state_]];
352 /* Read a lookahead token. */
353 if (looka_
== empty_
)
355 YYDPRINTF ((stderr
, "Reading a token: "));
359 /* Convert token to internal form. */
364 YYDPRINTF ((stderr
, "Now at end of input.\n"));
368 ilooka_
= translate_ (looka_
);
372 YYFPRINTF (stderr
, "Next token is %d (%s", looka_
, name_
[[ilooka_]]);
374 YYFPRINTF (stderr
, ")\n");
380 if (n_
< 0 || n_
> last_
|| check_
[[n_]] != ilooka_
)
383 /* Reduce or error. */
402 /* Shift the lookahead token. */
403 YYDPRINTF ((stderr
, "Shifting token %d (%s), ", looka_
, name_
[[ilooka_]]));
405 /* Discard the token being shifted unless it is eof. */
409 semantic_stack_
.push (value
);
410 location_stack_
.push (location
);
412 /* Count tokens shifted since error; after three, turn off error
420 /* Default action. */
422 n_
= defact_
[[state_]];
432 yyval
= semantic_stack_
[[1 - len_
]];
433 yyloc
= location_stack_
[[1 - len_
]];
437 yyval
= semantic_stack_
[[0]];
438 yyloc
= location_stack_
[[0]];
444 YYFPRINTF (stderr
, "Reducing via rule %d (line %d), ", n_
- 1, rline_
[[n_]]);
445 for (unsigned i
= prhs_
[[n_]];
447 YYFPRINTF (stderr
, "%s ", name_
[[rhs_
[i
]]]);
448 YYFPRINTF (stderr
, "-> %s\n", name_
[[r1_
[n_
]]]);
454 Slice
< LocationType
, LocationStack
> slice (location_stack_
, len_
);
455 YYLLOC_DEFAULT (yyloc
, slice
, len_
);
459 SemanticStack
& yyvsp (semantic_stack_
);
460 LocationStack
& yylsp (location_stack_
);
468 /* Line __line__ of __file__. */
469 #line __oline__ "__ofile__"
471 state_stack_
.pop (len_
);
472 semantic_stack_
.pop (len_
);
473 location_stack_
.pop (len_
);
478 YYFPRINTF (stderr
, "state stack now");
479 for (StateStack::ConstIterator i
= state_stack_
.begin ();
480 i
!= state_stack_
.end (); ++i
)
481 YYFPRINTF (stderr
, " %d", *i
);
482 YYFPRINTF (stderr
, "\n");
486 semantic_stack_
.push (yyval
);
487 location_stack_
.push (yyloc
);
489 /* Shift the result of the reduction. */
491 state_
= pgoto_
[[n_
- ntokens_
]] + state_stack_
[[0]];
492 if (state_
>= 0 && state_
<= last_
&& check_
[[state_]] == state_stack_
[[0]])
493 state_
= table_
[[state_]];
495 state_
= defgoto_
[[n_
- ntokens_
]];
498 /* Report and recover from errors. This is very incomplete. */
500 /* If not already recovering from an error, report this error. */
506 n_
= pact_
[[state_]];
507 if (n_
> flag_
&& n_
< last_
)
509 message
= "parse error, unexpected ";
510 message
+= name_
[[ilooka_]];
513 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
514 if (check_
[[x
+ n_
]] == x
)
519 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
520 if (check_
[[x
+ n_
]] == x
)
522 message
+= (!count
++) ? ", expecting " : " or ";
523 message
+= name_
[[x]];
530 message
= "parse error";
535 /* Error raised explicitly by an action. */
539 /* If just tried and failed to reuse lookahead token after an
540 error, discard it. */
542 /* Return failure if at end of input. */
545 YYDPRINTF ((stderr
, "Discarding token %d (%s).\n", looka_
, name_
[[ilooka_]]));
549 /* Else will try to reuse lookahead token after shifting the error
555 /* Pop the current state because it cannot handle the error token. */
558 if (!state_stack_
.height ())
560 state_
= (state_stack_
.pop (), state_stack_
[[0]]);
561 semantic_stack_
.pop ();
562 location_stack_
.pop ();;
567 YYFPRINTF (stderr
, "Error: state stack now");
568 for (StateStack::ConstIterator i
= state_stack_
.begin ();
569 i
!= state_stack_
.end (); ++i
)
570 YYFPRINTF (stderr
, " %d", *i
);
571 YYFPRINTF (stderr
, "\n");
576 n_
= pact_
[[state_]];
581 if (n_
< 0 || n_
> last_
|| check_
[[n_]] != terror_
)
598 YYDPRINTF ((stderr
, "Shifting error token, "));
600 semantic_stack_
.push (value
);
601 location_stack_
.push (location
);
619 looka_
= yylex (&value
, &location
);
621 looka_
= yylex (&value
);
625 /* YYPACT[[STATE-NUM]] -- Index in YYTABLE of the portion describing
628 yy::b4_name::pact_
[[]] =
633 /* YYDEFACT[[S]] -- default rule to reduce with in state S when YYTABLE
634 doesn't specify something else to do. Zero means the default is an
637 yy::b4_name::defact_
[[]] =
642 /* YYPGOTO[[NTERM-NUM]]. */
644 yy::b4_name::pgoto_
[[]] =
649 /* YYDEFGOTO[[NTERM-NUM]]. */
651 yy::b4_name::defgoto_
[[]] =
656 /* YYTABLE[[YYPACT[STATE-NUM]]]. What to do in state STATE-NUM. If
657 positive, shift that token. If negative, reduce the rule which
658 number is the opposite. If zero, do what YYDEFACT says. */
660 yy::b4_name::table_
[[]] =
667 yy::b4_name::check_
[[]] =
672 /* YYR1[[YYN]] -- Symbol number of symbol that rule YYN derives. */
673 const yy::b4_name::TokenNumberType
674 yy::b4_name::r1_
[[]] =
679 /* YYR2[[YYN]] -- Number of symbols composing right hand side of rule YYN. */
681 yy::b4_name::r2_
[[]] =
686 #if YYDEBUG || YYERROR_VERBOSE
687 /* YYTNAME[[SYMBOL-NUM]] -- String name of the symbol SYMBOL-NUM.
688 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
690 const yy::b4_name::name_
[[]] =
697 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
698 const yy::b4_name::RhsNumberType
699 yy::b4_name::rhs_
[[]] =
704 /* YYPRHS[[YYN]] -- Index of the first RHS symbol of rule number YYN in
707 yy::b4_name::prhs_
[[]] =
712 /* YYRLINE[[YYN]] -- source line where rule number YYN was defined. */
714 yy::b4_name::rline_
[[]] =
720 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
721 yy::b4_name::TokenNumberType
722 yy::b4_name::translate_ (int token
)
725 const TokenNumberType
730 if ((unsigned) token
<= user_token_number_max_
)
731 return translate_
[[token]];
736 const int yy::b4_name::eof_
= 0;
737 const int yy::b4_name::last_
= b4_last
;
738 const int yy::b4_name::flag_
= b4_flag
;
739 const int yy::b4_name::nnts_
= b4_nnts
;
740 const int yy::b4_name::nsym_
= b4_nsym
;
741 const int yy::b4_name::empty_
= -2;
742 const int yy::b4_name::final_
= b4_final
;
743 const int yy::b4_name::terror_
= 1;
744 const int yy::b4_name::errcode_
= 256;
745 const int yy::b4_name::ntokens_
= b4_ntokens
;
746 const int yy::b4_name::initdepth_
= b4_initdepth
;
748 const unsigned yy::b4_name::user_token_number_max_
= b4_user_token_number_max
;
749 const yy::b4_name::TokenNumberType
yy::b4_name::undef_token_
= b4_undef_token_number
;
756 #ifndef BISON_STACK_HH
757 # define BISON_STACK_HH
763 template < class T
, class S
= std::vector
< T
> >
768 typedef typename
S::iterator Iterator
;
769 typedef typename
S::const_iterator ConstIterator
;
775 Stack (unsigned n
) : seq_ (n
)
781 operator [[]] (int index
)
783 return seq_
[[height () - 1 + index
]];
788 operator [[]] (int index
) const
790 return seq_
[[height () - 1 + index
]];
822 inline ConstIterator
begin () const { return seq_
.begin (); }
823 inline ConstIterator
end () const { return seq_
.end (); }
830 template < class T
, class S
= Stack
< T
> >
835 Slice (const S
& stack
,
836 unsigned range
) : stack_ (stack
),
843 operator [[]] (unsigned index
) const
845 return stack_
[[index
- range_
]];
855 #endif // not BISON_STACK_HH
857 #output "location.hh"
860 #ifndef BISON_LOCATION_HH
861 # define BISON_LOCATION_HH
878 #endif // not BISON_LOCATION_HH