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_lhs_value([TYPE])
24 # --------------------
25 # Expansion of $<TYPE>$.
26 m4_define([b4_lhs_value
],
27 [yyval
[]m4_ifval([$
1], [.$
1])])
30 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
31 # --------------------------------------
32 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
34 m4_define([b4_rhs_value
],
35 [yyvsp@
<:@
m4_eval([$
2 - $
1])@
:>@
m4_ifval([$
3], [.$
3])])
41 m4_define([b4_lhs_location
],
45 # b4_rhs_location(RULE-LENGTH, NUM)
46 # ---------------------------------
47 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
49 m4_define([b4_rhs_location
],
50 [yylsp@
<:@
m4_eval([$
2 - $
1])@
:>@
])
53 # b4_token_defines(TOKEN-NAME, TOKEN-NUMBER)
54 # ------------------------------------------
55 # Output the definition of this token as #define.
56 m4_define([b4_token_define
],
61 # b4_token_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
62 # -------------------------------------------------------
63 # Output the definition of the tokens as #define.
64 m4_define([b4_token_defines
],
65 [m4_map([b4_token_define
], [$@
])])
67 m4_define_default([b4_input_suffix
], [.y
])
69 m4_define_default([b4_output_parser_suffix
],
70 [m4_translit(b4_input_suffix
, [yY
], [cC
])])
72 m4_define_default([b4_output_parser_name
],
73 [b4_output_prefix
[]b4_output_infix
[]b4_output_parser_suffix
[]])
76 m4_define_default([b4_output_header_suffix
],
77 [m4_translit(b4_input_suffix
, [yY
], [hH
])])
79 m4_define_default([b4_output_header_name
],
80 [b4_output_prefix
[]b4_output_infix
[]b4_output_header_suffix
[]])
82 m4_define_default([b4_header_guard
],
83 [m4_bpatsubst(m4_toupper([BISON_
]b4_output_header_name
),
84 [[^ABCDEFGHIJKLMNOPQRSTUVWXYZ
]], [_
])])
86 m4_define([b4_inherit
],
98 m4_define([b4_constructor
],
104 m4_define([b4_copyright
],
106 /* A Bison parser, made from b4_filename,
107 by GNU bison b4_version. */
109 /* Skeleton output parser for bison,
110 Copyright 2002 Free Software Foundation, Inc.
112 This program is free software; you can redistribute it and/or modify
113 it under the terms of the GNU General Public License as published by
114 the Free Software Foundation; either version 2, or (at your option)
117 This program is distributed in the hope that it will be useful,
118 but WITHOUT ANY WARRANTY; without even the implied warranty of
119 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
120 GNU General Public License for more details.
122 You should have received a copy of the GNU General Public License
123 along with this program; if not, write to the Free Software
124 Foundation, Inc., 59 Temple Place - Suite 330,
125 Boston, MA 02111-1307, USA. */
127 /* As a special exception, when this file is copied by Bison into a
128 Bison output file, you may use that output file without restriction.
129 This special exception was added by the Free Software Foundation
130 in version 1.24 of Bison. */])
133 #output "b4_output_header_name"
135 #ifndef b4_header_guard
136 # define b4_header_guard
139 #include "location.hh"
143 /* Using locations. */
144 #define YYLSP_NEEDED b4_locations_flag
146 /* Copy the first part of user declarations. */
150 b4_token_defines(b4_tokens
)
152 /* Enabling traces. */
154 # define YYDEBUG b4_debug
157 /* Enabling verbose error message. */
158 #ifndef YYERROR_VERBOSE
159 # define YYERROR_VERBOSE b4_error_verbose
163 m4_ifdef([b4_stype_line
],
164 [#line b4_stype_line "b4_filename"
168 # define YYSTYPE yystype
171 /* Copy the second part of user declarations. */
174 #line __oline__ "__ofile__"
175 #ifndef YYLLOC_DEFAULT
176 # define YYLLOC_DEFAULT(Current, Rhs, N) \
177 Current.last_line = Rhs[[N]].last_line; \
178 Current.last_column = Rhs[[N]].last_column;
181 m4_if(b4_locations_flag
, [0], [],
183 typedef struct yyltype
190 # define YYLTYPE yyltype
197 template < typename P
>
203 struct Traits
< b4_name
>
205 typedef b4_uint_type(b4_token_number_max
) TokenNumberType
;
206 typedef b4_sint_type(b4_rhs_number_max
) RhsNumberType
;
207 typedef int StateType
;
208 typedef yystype SemanticType
;
209 typedef b4_ltype LocationType
;
215 class b4_name b4_inherit
219 typedef Traits
< b4_name
>::TokenNumberType TokenNumberType
;
220 typedef Traits
< b4_name
>::RhsNumberType RhsNumberType
;
221 typedef Traits
< b4_name
>::StateType StateType
;
222 typedef Traits
< b4_name
>::SemanticType SemanticType
;
223 typedef Traits
< b4_name
>::LocationType LocationType
;
225 typedef Stack
< StateType
> StateStack
;
226 typedef Stack
< SemanticType
> SemanticStack
;
227 typedef Stack
< LocationType
> LocationStack
;
231 LocationType initlocation
[]b4_param
) :
232 b4_constructor
[]debug_ (debug
),
233 initlocation_ (initlocation
)
235 b4_name (bool debug
[]b4_param
) :
236 b4_constructor
[]debug_ (debug
)
245 virtual int parse ();
249 virtual void lex_ ();
250 virtual void error_ ();
251 virtual void print_ ();
254 StateStack state_stack_
;
255 SemanticStack semantic_stack_
;
256 LocationStack location_stack_
;
259 static const short pact_
[[]];
260 static const short defact_
[[]];
261 static const short pgoto_
[[]];
262 static const short defgoto_
[[]];
263 static const short table_
[[]];
264 static const short check_
[[]];
265 static const TokenNumberType r1_
[[]];
266 static const short r2_
[[]];
268 #if YYDEBUG || YYERROR_VERBOSE
269 static const char* const name_
[[]];
272 /* More tables, for debugging. */
274 static const RhsNumberType rhs_
[[]];
275 static const short prhs_
[[]];
276 static const short rline_
[[]];
279 /* Even more tables. */
280 static inline TokenNumberType
translate_ (int token
);
283 static const int eof_
;
284 static const int last_
;
285 static const int flag_
;
286 static const int nnts_
;
287 static const int nsym_
;
288 static const int empty_
;
289 static const int final_
;
290 static const int terror_
;
291 static const int errcode_
;
292 static const int ntokens_
;
293 static const int initdepth_
;
294 static const unsigned user_token_number_max_
;
295 static const TokenNumberType undef_token_
;
303 /* Lookahead and lookahead in internal form. */
310 /* Semantic value and location of lookahead token. */
312 LocationType location
;
318 /* Initial location. */
319 LocationType initlocation_
;
323 #endif /* not b4_header_guard */
325 #output "b4_output_prefix[]b4_output_infix[].cc"
328 #include "b4_output_header_name"
330 /* Enable debugging if requested. */
333 # define YYFPRINTF std::fprintf
334 # define YYDPRINTF(Args) \
340 # define YYDPRINTF(Args)
341 #endif /* !YYDEBUG */
344 yy::b4_name::parse ()
349 /* Initialize stack. */
350 state_stack_
= StateStack (0);
351 semantic_stack_
= SemanticStack (1);
352 location_stack_
= LocationStack (1);
354 /* Reserve initial space. The C parser needed that, but is it really
356 state_stack_
.reserve (initdepth_
);
357 semantic_stack_
.reserve (initdepth_
);
358 location_stack_
.reserve (initdepth_
);
364 location
= initlocation_
;
366 YYDPRINTF ((stderr
, "Starting parse\n"));
370 state_stack_
.push (state_
);
371 YYDPRINTF ((stderr
, "Entering state %d\n", state_
));
377 /* Try to take a decision without lookahead. */
378 n_
= pact_
[[state_]];
382 /* Read a lookahead token. */
383 if (looka_
== empty_
)
385 YYDPRINTF ((stderr
, "Reading a token: "));
389 /* Convert token to internal form. */
394 YYDPRINTF ((stderr
, "Now at end of input.\n"));
398 ilooka_
= translate_ (looka_
);
402 YYFPRINTF (stderr
, "Next token is %d (%s", looka_
, name_
[[ilooka_]]);
404 YYFPRINTF (stderr
, ")\n");
410 if (n_
< 0 || n_
> last_
|| check_
[[n_]] != ilooka_
)
413 /* Reduce or error. */
432 /* Shift the lookahead token. */
433 YYDPRINTF ((stderr
, "Shifting token %d (%s), ", looka_
, name_
[[ilooka_]]));
435 /* Discard the token being shifted unless it is eof. */
439 semantic_stack_
.push (value
);
440 location_stack_
.push (location
);
442 /* Count tokens shifted since error; after three, turn off error
450 /* Default action. */
452 n_
= defact_
[[state_]];
462 yyval
= semantic_stack_
[[1 - len_
]];
463 yyloc
= location_stack_
[[1 - len_
]];
467 yyval
= semantic_stack_
[[0]];
468 yyloc
= location_stack_
[[0]];
474 YYFPRINTF (stderr
, "Reducing via rule %d (line %d), ", n_
- 1, rline_
[[n_]]);
475 for (unsigned i
= prhs_
[[n_]];
477 YYFPRINTF (stderr
, "%s ", name_
[[rhs_
[i
]]]);
478 YYFPRINTF (stderr
, "-> %s\n", name_
[[r1_
[n_
]]]);
484 Slice
< LocationType
, LocationStack
> slice (location_stack_
, len_
);
485 YYLLOC_DEFAULT (yyloc
, slice
, len_
);
489 SemanticStack
& yyvsp (semantic_stack_
);
490 LocationStack
& yylsp (location_stack_
);
498 /* Line __line__ of __file__. */
499 #line __oline__ "__ofile__"
501 state_stack_
.pop (len_
);
502 semantic_stack_
.pop (len_
);
503 location_stack_
.pop (len_
);
508 YYFPRINTF (stderr
, "state stack now");
509 for (StateStack::ConstIterator i
= state_stack_
.begin ();
510 i
!= state_stack_
.end (); ++i
)
511 YYFPRINTF (stderr
, " %d", *i
);
512 YYFPRINTF (stderr
, "\n");
516 semantic_stack_
.push (yyval
);
517 location_stack_
.push (yyloc
);
519 /* Shift the result of the reduction. */
521 state_
= pgoto_
[[n_
- ntokens_
]] + state_stack_
[[0]];
522 if (state_
>= 0 && state_
<= last_
&& check_
[[state_]] == state_stack_
[[0]])
523 state_
= table_
[[state_]];
525 state_
= defgoto_
[[n_
- ntokens_
]];
528 /* Report and recover from errors. This is very incomplete. */
530 /* If not already recovering from an error, report this error. */
536 n_
= pact_
[[state_]];
537 if (n_
> flag_
&& n_
< last_
)
539 message
= "parse error, unexpected ";
540 message
+= name_
[[ilooka_]];
543 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
544 if (check_
[[x
+ n_
]] == x
)
549 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
550 if (check_
[[x
+ n_
]] == x
)
552 message
+= (!count
++) ? ", expecting " : " or ";
553 message
+= name_
[[x]];
560 message
= "parse error";
565 /* Error raised explicitly by an action. */
569 /* If just tried and failed to reuse lookahead token after an
570 error, discard it. */
572 /* Return failure if at end of input. */
575 YYDPRINTF ((stderr
, "Discarding token %d (%s).\n", looka_
, name_
[[ilooka_]]));
579 /* Else will try to reuse lookahead token after shifting the error
585 /* Pop the current state because it cannot handle the error token. */
588 if (!state_stack_
.height ())
590 state_
= (state_stack_
.pop (), state_stack_
[[0]]);
591 semantic_stack_
.pop ();
592 location_stack_
.pop ();;
597 YYFPRINTF (stderr
, "Error: state stack now");
598 for (StateStack::ConstIterator i
= state_stack_
.begin ();
599 i
!= state_stack_
.end (); ++i
)
600 YYFPRINTF (stderr
, " %d", *i
);
601 YYFPRINTF (stderr
, "\n");
606 n_
= pact_
[[state_]];
611 if (n_
< 0 || n_
> last_
|| check_
[[n_]] != terror_
)
628 YYDPRINTF ((stderr
, "Shifting error token, "));
630 semantic_stack_
.push (value
);
631 location_stack_
.push (location
);
649 looka_
= yylex (&value
, &location
);
651 looka_
= yylex (&value
);
655 /* YYPACT[[STATE-NUM]] -- Index in YYTABLE of the portion describing
658 yy::b4_name::pact_
[[]] =
663 /* YYDEFACT[[S]] -- default rule to reduce with in state S when YYTABLE
664 doesn't specify something else to do. Zero means the default is an
667 yy::b4_name::defact_
[[]] =
672 /* YYPGOTO[[NTERM-NUM]]. */
674 yy::b4_name::pgoto_
[[]] =
679 /* YYDEFGOTO[[NTERM-NUM]]. */
681 yy::b4_name::defgoto_
[[]] =
686 /* YYTABLE[[YYPACT[STATE-NUM]]]. What to do in state STATE-NUM. If
687 positive, shift that token. If negative, reduce the rule which
688 number is the opposite. If zero, do what YYDEFACT says. */
690 yy::b4_name::table_
[[]] =
697 yy::b4_name::check_
[[]] =
702 /* YYR1[[YYN]] -- Symbol number of symbol that rule YYN derives. */
703 const yy::b4_name::TokenNumberType
704 yy::b4_name::r1_
[[]] =
709 /* YYR2[[YYN]] -- Number of symbols composing right hand side of rule YYN. */
711 yy::b4_name::r2_
[[]] =
716 #if YYDEBUG || YYERROR_VERBOSE
717 /* YYTNAME[[SYMBOL-NUM]] -- String name of the symbol SYMBOL-NUM.
718 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
720 const yy::b4_name::name_
[[]] =
727 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
728 const yy::b4_name::RhsNumberType
729 yy::b4_name::rhs_
[[]] =
734 /* YYPRHS[[YYN]] -- Index of the first RHS symbol of rule number YYN in
737 yy::b4_name::prhs_
[[]] =
742 /* YYRLINE[[YYN]] -- source line where rule number YYN was defined. */
744 yy::b4_name::rline_
[[]] =
750 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
751 yy::b4_name::TokenNumberType
752 yy::b4_name::translate_ (int token
)
755 const TokenNumberType
760 if ((unsigned) token
<= user_token_number_max_
)
761 return translate_
[[token]];
766 const int yy::b4_name::eof_
= 0;
767 const int yy::b4_name::last_
= b4_last
;
768 const int yy::b4_name::flag_
= b4_flag
;
769 const int yy::b4_name::nnts_
= b4_nnts
;
770 const int yy::b4_name::nsym_
= b4_nsym
;
771 const int yy::b4_name::empty_
= -2;
772 const int yy::b4_name::final_
= b4_final
;
773 const int yy::b4_name::terror_
= 1;
774 const int yy::b4_name::errcode_
= 256;
775 const int yy::b4_name::ntokens_
= b4_ntokens
;
776 const int yy::b4_name::initdepth_
= b4_initdepth
;
778 const unsigned yy::b4_name::user_token_number_max_
= b4_user_token_number_max
;
779 const yy::b4_name::TokenNumberType
yy::b4_name::undef_token_
= b4_undef_token_number
;
786 #ifndef BISON_STACK_HH
787 # define BISON_STACK_HH
793 template < class T
, class S
= std::vector
< T
> >
798 typedef typename
S::iterator Iterator
;
799 typedef typename
S::const_iterator ConstIterator
;
805 Stack (unsigned n
) : seq_ (n
)
811 operator [[]] (int index
)
813 return seq_
[[height () - 1 + index
]];
818 operator [[]] (int index
) const
820 return seq_
[[height () - 1 + index
]];
852 inline ConstIterator
begin () const { return seq_
.begin (); }
853 inline ConstIterator
end () const { return seq_
.end (); }
860 template < class T
, class S
= Stack
< T
> >
865 Slice (const S
& stack
,
866 unsigned range
) : stack_ (stack
),
873 operator [[]] (unsigned index
) const
875 return stack_
[[index
- range_
]];
885 #endif // not BISON_STACK_HH
887 #output "location.hh"
890 #ifndef BISON_LOCATION_HH
891 # define BISON_LOCATION_HH
908 #endif // not BISON_LOCATION_HH