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 #line __oline__ "__ofile__"
141 #ifndef YYLLOC_DEFAULT
142 # define YYLLOC_DEFAULT(Current, Rhs, N) \
143 Current.last_line = Rhs[[N]].last_line; \
144 Current.last_column = Rhs[[N]].last_column;
147 m4_if(b4_locations_flag
, [0], [],
149 typedef struct yyltype
156 # define YYLTYPE yyltype
163 template < typename P
>
169 struct Traits
< b4_name
>
171 typedef b4_uint_type(b4_token_number_max
) TokenNumberType
;
172 typedef b4_sint_type(b4_rhs_number_max
) RhsNumberType
;
173 typedef int StateType
;
174 typedef yystype SemanticType
;
175 typedef b4_ltype LocationType
;
181 class b4_name b4_inherit
185 typedef Traits
< b4_name
>::TokenNumberType TokenNumberType
;
186 typedef Traits
< b4_name
>::RhsNumberType RhsNumberType
;
187 typedef Traits
< b4_name
>::StateType StateType
;
188 typedef Traits
< b4_name
>::SemanticType SemanticType
;
189 typedef Traits
< b4_name
>::LocationType LocationType
;
191 typedef Stack
< StateType
> StateStack
;
192 typedef Stack
< SemanticType
> SemanticStack
;
193 typedef Stack
< LocationType
> LocationStack
;
197 LocationType initlocation
[]b4_param
) :
198 b4_constructor
[]debug_ (debug
),
199 initlocation_ (initlocation
)
201 b4_name (bool debug
[]b4_param
) :
202 b4_constructor
[]debug_ (debug
)
211 virtual int parse ();
215 virtual void lex_ ();
216 virtual void error_ ();
217 virtual void print_ ();
220 StateStack state_stack_
;
221 SemanticStack semantic_stack_
;
222 LocationStack location_stack_
;
225 static const short pact_
[[]];
226 static const short defact_
[[]];
227 static const short pgoto_
[[]];
228 static const short defgoto_
[[]];
229 static const short table_
[[]];
230 static const short check_
[[]];
231 static const short r1_
[[]];
232 static const short r2_
[[]];
234 #if YYDEBUG || YYERROR_VERBOSE
235 static const char* const name_
[[]];
238 /* More tables, for debugging. */
240 static const RhsNumberType rhs_
[[]];
241 static const short prhs_
[[]];
242 static const short rline_
[[]];
245 /* Even more tables. */
246 static inline TokenNumberType
translate_ (int token
);
249 static const int eof_
;
250 static const int last_
;
251 static const int flag_
;
252 static const int nnts_
;
253 static const int nsym_
;
254 static const int empty_
;
255 static const int final_
;
256 static const int terror_
;
257 static const int errcode_
;
258 static const int ntokens_
;
259 static const int initdepth_
;
260 static const unsigned maxtok_
;
268 /* Lookahead and lookahead in internal form. */
275 /* Semantic value and location of lookahead token. */
277 LocationType location
;
283 /* Initial location. */
284 LocationType initlocation_
;
288 #endif /* not b4_header_guard */
290 #output "b4_output_prefix[]b4_output_infix[].cc"
293 #include "b4_output_header_name"
295 /* Enable debugging if requested. */
298 # define YYFPRINTF std::fprintf
299 # define YYDPRINTF(Args) \
305 # define YYDPRINTF(Args)
306 #endif /* !YYDEBUG */
309 yy::b4_name::parse ()
314 /* Initialize stack. */
315 state_stack_
= StateStack (0);
316 semantic_stack_
= SemanticStack (1);
317 location_stack_
= LocationStack (1);
319 /* Reserve initial space. The C parser needed that, but is it really
321 state_stack_
.reserve (initdepth_
);
322 semantic_stack_
.reserve (initdepth_
);
323 location_stack_
.reserve (initdepth_
);
329 location
= initlocation_
;
331 YYDPRINTF ((stderr
, "Starting parse\n"));
335 state_stack_
.push (state_
);
336 YYDPRINTF ((stderr
, "Entering state %d\n", state_
));
342 /* Try to take a decision without lookahead. */
343 n_
= pact_
[[state_]];
347 /* Read a lookahead token. */
348 if (looka_
== empty_
)
350 YYDPRINTF ((stderr
, "Reading a token: "));
354 /* Convert token to internal form. */
359 YYDPRINTF ((stderr
, "Now at end of input.\n"));
363 ilooka_
= translate_ (looka_
);
367 YYFPRINTF (stderr
, "Next token is %d (%s", looka_
, name_
[[ilooka_]]);
369 YYFPRINTF (stderr
, ")\n");
375 if (n_
< 0 || n_
> last_
|| check_
[[n_]] != ilooka_
)
378 /* Reduce or error. */
397 /* Shift the lookahead token. */
398 YYDPRINTF ((stderr
, "Shifting token %d (%s), ", looka_
, name_
[[ilooka_]]));
400 /* Discard the token being shifted unless it is eof. */
404 semantic_stack_
.push (value
);
405 location_stack_
.push (location
);
407 /* Count tokens shifted since error; after three, turn off error
415 /* Default action. */
417 n_
= defact_
[[state_]];
427 yyval
= semantic_stack_
[[1 - len_
]];
428 yyloc
= location_stack_
[[1 - len_
]];
432 yyval
= semantic_stack_
[[0]];
433 yyloc
= location_stack_
[[0]];
439 YYFPRINTF (stderr
, "Reducing via rule %d (line %d), ", n_
- 1, rline_
[[n_]]);
440 for (unsigned i
= prhs_
[[n_]];
442 YYFPRINTF (stderr
, "%s ", name_
[[rhs_
[i
]]]);
443 YYFPRINTF (stderr
, "-> %s\n", name_
[[r1_
[n_
]]]);
449 Slice
< LocationType
, LocationStack
> slice (location_stack_
, len_
);
450 YYLLOC_DEFAULT (yyloc
, slice
, len_
);
454 SemanticStack
& yyvsp (semantic_stack_
);
455 LocationStack
& yylsp (location_stack_
);
463 /* Line __line__ of __file__. */
464 #line __oline__ "__ofile__"
466 state_stack_
.pop (len_
);
467 semantic_stack_
.pop (len_
);
468 location_stack_
.pop (len_
);
473 YYFPRINTF (stderr
, "state stack now");
474 for (StateStack::ConstIterator i
= state_stack_
.begin ();
475 i
!= state_stack_
.end (); ++i
)
476 YYFPRINTF (stderr
, " %d", *i
);
477 YYFPRINTF (stderr
, "\n");
481 semantic_stack_
.push (yyval
);
482 location_stack_
.push (yyloc
);
484 /* Shift the result of the reduction. */
486 state_
= pgoto_
[[n_
- ntokens_
]] + state_stack_
[[0]];
487 if (state_
>= 0 && state_
<= last_
&& check_
[[state_]] == state_stack_
[[0]])
488 state_
= table_
[[state_]];
490 state_
= defgoto_
[[n_
- ntokens_
]];
493 /* Report and recover from errors. This is very incomplete. */
495 /* If not already recovering from an error, report this error. */
501 n_
= pact_
[[state_]];
502 if (n_
> flag_
&& n_
< last_
)
504 message
= "parse error, unexpected ";
505 message
+= name_
[[ilooka_]];
508 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
509 if (check_
[[x
+ n_
]] == x
)
514 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
515 if (check_
[[x
+ n_
]] == x
)
517 message
+= (!count
++) ? ", expecting " : " or ";
518 message
+= name_
[[x]];
525 message
= "parse error";
530 /* Error raised explicitly by an action. */
534 /* If just tried and failed to reuse lookahead token after an
535 error, discard it. */
537 /* Return failure if at end of input. */
540 YYDPRINTF ((stderr
, "Discarding token %d (%s).\n", looka_
, name_
[[ilooka_]]));
544 /* Else will try to reuse lookahead token after shifting the error
550 /* Pop the current state because it cannot handle the error token. */
553 if (!state_stack_
.height ())
555 state_
= (state_stack_
.pop (), state_stack_
[[0]]);
556 semantic_stack_
.pop ();
557 location_stack_
.pop ();;
562 YYFPRINTF (stderr
, "Error: state stack now");
563 for (StateStack::ConstIterator i
= state_stack_
.begin ();
564 i
!= state_stack_
.end (); ++i
)
565 YYFPRINTF (stderr
, " %d", *i
);
566 YYFPRINTF (stderr
, "\n");
571 n_
= pact_
[[state_]];
576 if (n_
< 0 || n_
> last_
|| check_
[[n_]] != terror_
)
593 YYDPRINTF ((stderr
, "Shifting error token, "));
595 semantic_stack_
.push (value
);
596 location_stack_
.push (location
);
614 looka_
= yylex (&value
, &location
);
616 looka_
= yylex (&value
);
620 /* YYPACT[[STATE-NUM]] -- Index in YYTABLE of the portion describing
623 yy::b4_name::pact_
[[]] =
628 /* YYDEFACT[[S]] -- default rule to reduce with in state S when YYTABLE
629 doesn't specify something else to do. Zero means the default is an
632 yy::b4_name::defact_
[[]] =
637 /* YYPGOTO[[NTERM-NUM]]. */
639 yy::b4_name::pgoto_
[[]] =
644 /* YYDEFGOTO[[NTERM-NUM]]. */
646 yy::b4_name::defgoto_
[[]] =
651 /* YYTABLE[[YYPACT[STATE-NUM]]]. What to do in state STATE-NUM. If
652 positive, shift that token. If negative, reduce the rule which
653 number is the opposite. If zero, do what YYDEFACT says. */
655 yy::b4_name::table_
[[]] =
662 yy::b4_name::check_
[[]] =
667 /* YYR1[[YYN]] -- Symbol number of symbol that rule YYN derives. */
669 yy::b4_name::r1_
[[]] =
674 /* YYR2[[YYN]] -- Number of symbols composing right hand side of rule YYN. */
676 yy::b4_name::r2_
[[]] =
681 #if YYDEBUG || YYERROR_VERBOSE
682 /* YYTNAME[[SYMBOL-NUM]] -- String name of the symbol SYMBOL-NUM.
683 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
685 const yy::b4_name::name_
[[]] =
692 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
693 const yy::b4_name::RhsNumberType
694 yy::b4_name::rhs_
[[]] =
699 /* YYPRHS[[YYN]] -- Index of the first RHS symbol of rule number YYN in
702 yy::b4_name::prhs_
[[]] =
707 /* YYRLINE[[YYN]] -- source line where rule number YYN was defined. */
709 yy::b4_name::rline_
[[]] =
715 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
716 yy::b4_name::TokenNumberType
717 yy::b4_name::translate_ (int token
)
720 const TokenNumberType
725 return (unsigned)(token
) <= maxtok_
? translate_
[[token]] : nsym_
;
728 const int yy::b4_name::eof_
= 0;
729 const int yy::b4_name::last_
= b4_last
;
730 const int yy::b4_name::flag_
= b4_flag
;
731 const int yy::b4_name::nnts_
= b4_nnts
;
732 const int yy::b4_name::nsym_
= b4_nsym
;
733 const int yy::b4_name::empty_
= -2;
734 const int yy::b4_name::final_
= b4_final
;
735 const int yy::b4_name::terror_
= 1;
736 const int yy::b4_name::errcode_
= 256;
737 const int yy::b4_name::ntokens_
= b4_ntokens
;
738 const int yy::b4_name::initdepth_
= b4_initdepth
;
740 const unsigned yy::b4_name::maxtok_
= b4_maxtok
;
747 #ifndef BISON_STACK_HH
748 # define BISON_STACK_HH
754 template < class T
, class S
= std::vector
< T
> >
759 typedef typename
S::iterator Iterator
;
760 typedef typename
S::const_iterator ConstIterator
;
766 Stack (unsigned n
) : seq_ (n
)
772 operator [[]] (int index
)
774 return seq_
[[height () - 1 + index
]];
779 operator [[]] (int index
) const
781 return seq_
[[height () - 1 + index
]];
813 inline ConstIterator
begin () const { return seq_
.begin (); }
814 inline ConstIterator
end () const { return seq_
.end (); }
821 template < class T
, class S
= Stack
< T
> >
826 Slice (const S
& stack
,
827 unsigned range
) : stack_ (stack
),
834 operator [[]] (unsigned index
) const
836 return stack_
[[index
- range_
]];
846 #endif // not BISON_STACK_HH
848 #output "location.hh"
851 #ifndef BISON_LOCATION_HH
852 # define BISON_LOCATION_HH
869 #endif // not BISON_LOCATION_HH