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 TokenNumberType 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 user_token_number_max_
;
261 static const TokenNumberType undef_token_
;
269 /* Lookahead and lookahead in internal form. */
276 /* Semantic value and location of lookahead token. */
278 LocationType location
;
284 /* Initial location. */
285 LocationType initlocation_
;
289 #endif /* not b4_header_guard */
291 #output "b4_output_prefix[]b4_output_infix[].cc"
294 #include "b4_output_header_name"
296 /* Enable debugging if requested. */
299 # define YYFPRINTF std::fprintf
300 # define YYDPRINTF(Args) \
306 # define YYDPRINTF(Args)
307 #endif /* !YYDEBUG */
310 yy::b4_name::parse ()
315 /* Initialize stack. */
316 state_stack_
= StateStack (0);
317 semantic_stack_
= SemanticStack (1);
318 location_stack_
= LocationStack (1);
320 /* Reserve initial space. The C parser needed that, but is it really
322 state_stack_
.reserve (initdepth_
);
323 semantic_stack_
.reserve (initdepth_
);
324 location_stack_
.reserve (initdepth_
);
330 location
= initlocation_
;
332 YYDPRINTF ((stderr
, "Starting parse\n"));
336 state_stack_
.push (state_
);
337 YYDPRINTF ((stderr
, "Entering state %d\n", state_
));
343 /* Try to take a decision without lookahead. */
344 n_
= pact_
[[state_]];
348 /* Read a lookahead token. */
349 if (looka_
== empty_
)
351 YYDPRINTF ((stderr
, "Reading a token: "));
355 /* Convert token to internal form. */
360 YYDPRINTF ((stderr
, "Now at end of input.\n"));
364 ilooka_
= translate_ (looka_
);
368 YYFPRINTF (stderr
, "Next token is %d (%s", looka_
, name_
[[ilooka_]]);
370 YYFPRINTF (stderr
, ")\n");
376 if (n_
< 0 || n_
> last_
|| check_
[[n_]] != ilooka_
)
379 /* Reduce or error. */
398 /* Shift the lookahead token. */
399 YYDPRINTF ((stderr
, "Shifting token %d (%s), ", looka_
, name_
[[ilooka_]]));
401 /* Discard the token being shifted unless it is eof. */
405 semantic_stack_
.push (value
);
406 location_stack_
.push (location
);
408 /* Count tokens shifted since error; after three, turn off error
416 /* Default action. */
418 n_
= defact_
[[state_]];
428 yyval
= semantic_stack_
[[1 - len_
]];
429 yyloc
= location_stack_
[[1 - len_
]];
433 yyval
= semantic_stack_
[[0]];
434 yyloc
= location_stack_
[[0]];
440 YYFPRINTF (stderr
, "Reducing via rule %d (line %d), ", n_
- 1, rline_
[[n_]]);
441 for (unsigned i
= prhs_
[[n_]];
443 YYFPRINTF (stderr
, "%s ", name_
[[rhs_
[i
]]]);
444 YYFPRINTF (stderr
, "-> %s\n", name_
[[r1_
[n_
]]]);
450 Slice
< LocationType
, LocationStack
> slice (location_stack_
, len_
);
451 YYLLOC_DEFAULT (yyloc
, slice
, len_
);
455 SemanticStack
& yyvsp (semantic_stack_
);
456 LocationStack
& yylsp (location_stack_
);
464 /* Line __line__ of __file__. */
465 #line __oline__ "__ofile__"
467 state_stack_
.pop (len_
);
468 semantic_stack_
.pop (len_
);
469 location_stack_
.pop (len_
);
474 YYFPRINTF (stderr
, "state stack now");
475 for (StateStack::ConstIterator i
= state_stack_
.begin ();
476 i
!= state_stack_
.end (); ++i
)
477 YYFPRINTF (stderr
, " %d", *i
);
478 YYFPRINTF (stderr
, "\n");
482 semantic_stack_
.push (yyval
);
483 location_stack_
.push (yyloc
);
485 /* Shift the result of the reduction. */
487 state_
= pgoto_
[[n_
- ntokens_
]] + state_stack_
[[0]];
488 if (state_
>= 0 && state_
<= last_
&& check_
[[state_]] == state_stack_
[[0]])
489 state_
= table_
[[state_]];
491 state_
= defgoto_
[[n_
- ntokens_
]];
494 /* Report and recover from errors. This is very incomplete. */
496 /* If not already recovering from an error, report this error. */
502 n_
= pact_
[[state_]];
503 if (n_
> flag_
&& n_
< last_
)
505 message
= "parse error, unexpected ";
506 message
+= name_
[[ilooka_]];
509 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
510 if (check_
[[x
+ n_
]] == x
)
515 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
516 if (check_
[[x
+ n_
]] == x
)
518 message
+= (!count
++) ? ", expecting " : " or ";
519 message
+= name_
[[x]];
526 message
= "parse error";
531 /* Error raised explicitly by an action. */
535 /* If just tried and failed to reuse lookahead token after an
536 error, discard it. */
538 /* Return failure if at end of input. */
541 YYDPRINTF ((stderr
, "Discarding token %d (%s).\n", looka_
, name_
[[ilooka_]]));
545 /* Else will try to reuse lookahead token after shifting the error
551 /* Pop the current state because it cannot handle the error token. */
554 if (!state_stack_
.height ())
556 state_
= (state_stack_
.pop (), state_stack_
[[0]]);
557 semantic_stack_
.pop ();
558 location_stack_
.pop ();;
563 YYFPRINTF (stderr
, "Error: state stack now");
564 for (StateStack::ConstIterator i
= state_stack_
.begin ();
565 i
!= state_stack_
.end (); ++i
)
566 YYFPRINTF (stderr
, " %d", *i
);
567 YYFPRINTF (stderr
, "\n");
572 n_
= pact_
[[state_]];
577 if (n_
< 0 || n_
> last_
|| check_
[[n_]] != terror_
)
594 YYDPRINTF ((stderr
, "Shifting error token, "));
596 semantic_stack_
.push (value
);
597 location_stack_
.push (location
);
615 looka_
= yylex (&value
, &location
);
617 looka_
= yylex (&value
);
621 /* YYPACT[[STATE-NUM]] -- Index in YYTABLE of the portion describing
624 yy::b4_name::pact_
[[]] =
629 /* YYDEFACT[[S]] -- default rule to reduce with in state S when YYTABLE
630 doesn't specify something else to do. Zero means the default is an
633 yy::b4_name::defact_
[[]] =
638 /* YYPGOTO[[NTERM-NUM]]. */
640 yy::b4_name::pgoto_
[[]] =
645 /* YYDEFGOTO[[NTERM-NUM]]. */
647 yy::b4_name::defgoto_
[[]] =
652 /* YYTABLE[[YYPACT[STATE-NUM]]]. What to do in state STATE-NUM. If
653 positive, shift that token. If negative, reduce the rule which
654 number is the opposite. If zero, do what YYDEFACT says. */
656 yy::b4_name::table_
[[]] =
663 yy::b4_name::check_
[[]] =
668 /* YYR1[[YYN]] -- Symbol number of symbol that rule YYN derives. */
669 const yy::b4_name::TokenNumberType
670 yy::b4_name::r1_
[[]] =
675 /* YYR2[[YYN]] -- Number of symbols composing right hand side of rule YYN. */
677 yy::b4_name::r2_
[[]] =
682 #if YYDEBUG || YYERROR_VERBOSE
683 /* YYTNAME[[SYMBOL-NUM]] -- String name of the symbol SYMBOL-NUM.
684 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
686 const yy::b4_name::name_
[[]] =
693 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
694 const yy::b4_name::RhsNumberType
695 yy::b4_name::rhs_
[[]] =
700 /* YYPRHS[[YYN]] -- Index of the first RHS symbol of rule number YYN in
703 yy::b4_name::prhs_
[[]] =
708 /* YYRLINE[[YYN]] -- source line where rule number YYN was defined. */
710 yy::b4_name::rline_
[[]] =
716 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
717 yy::b4_name::TokenNumberType
718 yy::b4_name::translate_ (int token
)
721 const TokenNumberType
726 if ((unsigned) token
<= user_token_number_max_
)
727 return translate_
[[token]];
732 const int yy::b4_name::eof_
= 0;
733 const int yy::b4_name::last_
= b4_last
;
734 const int yy::b4_name::flag_
= b4_flag
;
735 const int yy::b4_name::nnts_
= b4_nnts
;
736 const int yy::b4_name::nsym_
= b4_nsym
;
737 const int yy::b4_name::empty_
= -2;
738 const int yy::b4_name::final_
= b4_final
;
739 const int yy::b4_name::terror_
= 1;
740 const int yy::b4_name::errcode_
= 256;
741 const int yy::b4_name::ntokens_
= b4_ntokens
;
742 const int yy::b4_name::initdepth_
= b4_initdepth
;
744 const unsigned yy::b4_name::user_token_number_max_
= b4_user_token_number_max
;
745 const yy::b4_name::TokenNumberType
yy::b4_name::undef_token_
= b4_undef_token_number
;
752 #ifndef BISON_STACK_HH
753 # define BISON_STACK_HH
759 template < class T
, class S
= std::vector
< T
> >
764 typedef typename
S::iterator Iterator
;
765 typedef typename
S::const_iterator ConstIterator
;
771 Stack (unsigned n
) : seq_ (n
)
777 operator [[]] (int index
)
779 return seq_
[[height () - 1 + index
]];
784 operator [[]] (int index
) const
786 return seq_
[[height () - 1 + index
]];
818 inline ConstIterator
begin () const { return seq_
.begin (); }
819 inline ConstIterator
end () const { return seq_
.end (); }
826 template < class T
, class S
= Stack
< T
> >
831 Slice (const S
& stack
,
832 unsigned range
) : stack_ (stack
),
839 operator [[]] (unsigned index
) const
841 return stack_
[[index
- range_
]];
851 #endif // not BISON_STACK_HH
853 #output "location.hh"
856 #ifndef BISON_LOCATION_HH
857 # define BISON_LOCATION_HH
874 #endif // not BISON_LOCATION_HH