3 # b4_token_defines(TOKEN-NAME, TOKEN-NUMBER)
4 # ------------------------------------------
5 # Output the definition of this token as #define.
6 m4_define([b4_token_define
],
11 # b4_token_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
12 # -------------------------------------------------------
13 # Output the definition of the tokens as #define.
14 m4_define([b4_token_defines
],
15 [m4_map([b4_token_define
], [$@
])])
17 m4_define_default([b4_input_suffix
], [.y
])
19 m4_define_default([b4_output_parser_suffix
],
20 [m4_translit(b4_input_suffix
, [yY
], [cC
])])
22 m4_define_default([b4_output_parser_name
],
23 [b4_output_prefix
[]b4_output_infix
[]b4_output_parser_suffix
[]])
26 m4_define_default([b4_output_header_suffix
],
27 [m4_translit(b4_input_suffix
, [yY
], [hH
])])
29 m4_define_default([b4_output_header_name
],
30 [b4_output_prefix
[]b4_output_infix
[]b4_output_header_suffix
[]])
32 m4_define_default([b4_header_guard
],
33 [m4_bpatsubst(m4_toupper([BISON_
]b4_output_header_name
),
34 [[^ABCDEFGHIJKLMNOPQRSTUVWXYZ
]], [_
])])
36 m4_define([b4_inherit
],
48 m4_define([b4_constructor
],
54 m4_define([b4_copyright
],
56 /* A Bison parser, made from b4_filename,
57 by GNU bison b4_version. */
59 /* Skeleton output parser for bison,
60 Copyright 2002 Free Software Foundation, Inc.
62 This program is free software; you can redistribute it and/or modify
63 it under the terms of the GNU General Public License as published by
64 the Free Software Foundation; either version 2, or (at your option)
67 This program is distributed in the hope that it will be useful,
68 but WITHOUT ANY WARRANTY; without even the implied warranty of
69 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
70 GNU General Public License for more details.
72 You should have received a copy of the GNU General Public License
73 along with this program; if not, write to the Free Software
74 Foundation, Inc., 59 Temple Place - Suite 330,
75 Boston, MA 02111-1307, USA. */
77 /* As a special exception, when this file is copied by Bison into a
78 Bison output file, you may use that output file without restriction.
79 This special exception was added by the Free Software Foundation
80 in version 1.24 of Bison. */])
83 #output "b4_output_header_name"
85 #ifndef b4_header_guard
86 # define b4_header_guard
89 #include "location.hh"
93 /* Using locations. */
94 #define YYLSP_NEEDED b4_locations_flag
101 /* Enabling traces. */
103 # define YYDEBUG b4_debug
106 /* Enabling verbose error message. */
107 #ifndef YYERROR_VERBOSE
108 # define YYERROR_VERBOSE b4_error_verbose
114 # define YYSTYPE yystype
117 #ifndef YYLLOC_DEFAULT
118 # define YYLLOC_DEFAULT(Current, Rhs, N) \
119 Current.last_line = Rhs[[N]].last_line; \
120 Current.last_column = Rhs[[N]].last_column;
123 m4_if(b4_locations_flag
, [0], [],
125 typedef struct yyltype
132 # define YYLTYPE yyltype
139 template < typename P
>
145 struct Traits
< b4_name
>
147 typedef int StateType
;
148 typedef yystype SemanticType
;
149 typedef b4_ltype LocationType
;
155 class b4_name b4_inherit
159 typedef Traits
< b4_name
>::StateType StateType
;
160 typedef Traits
< b4_name
>::SemanticType SemanticType
;
161 typedef Traits
< b4_name
>::LocationType LocationType
;
163 typedef Stack
< StateType
> StateStack
;
164 typedef Stack
< SemanticType
> SemanticStack
;
165 typedef Stack
< LocationType
> LocationStack
;
169 LocationType initlocation
[]b4_param
) :
170 b4_constructor
[]debug_ (debug
),
171 initlocation_ (initlocation
)
173 b4_name (bool debug
[]b4_param
) :
174 b4_constructor
[]debug_ (debug
)
183 virtual int parse ();
187 virtual void lex_ ();
188 virtual void error_ ();
189 virtual void print_ ();
192 StateStack state_stack_
;
193 SemanticStack semantic_stack_
;
194 LocationStack location_stack_
;
197 static const short pact_
[[]];
198 static const short defact_
[[]];
199 static const short pgoto_
[[]];
200 static const short defgoto_
[[]];
201 static const short table_
[[]];
202 static const short check_
[[]];
203 static const short r1_
[[]];
204 static const short r2_
[[]];
206 #if YYDEBUG || YYERROR_VERBOSE
207 static const char* const name_
[[]];
210 /* More tables, for debugging. */
212 static const short rhs_
[[]];
213 static const short prhs_
[[]];
214 static const short rline_
[[]];
217 /* Even more tables. */
218 static inline char translate_ (int token
);
221 static const int eof_
;
222 static const int last_
;
223 static const int flag_
;
224 static const int nnts_
;
225 static const int nsym_
;
226 static const int empty_
;
227 static const int final_
;
228 static const int terror_
;
229 static const int errcode_
;
230 static const int ntokens_
;
231 static const int initdepth_
;
232 static const unsigned maxtok_
;
240 /* Lookahead and lookahead in internal form. */
247 /* Semantic value and location of lookahead token. */
249 LocationType location
;
255 /* Initial location. */
256 LocationType initlocation_
;
260 #endif /* not b4_header_guard */
262 #output "b4_output_prefix[]b4_output_infix[].cc"
265 #include "b4_output_header_name"
267 /* Enable debugging if requested. */
270 # define YYFPRINTF std::fprintf
271 # define YYDPRINTF(Args) \
277 # define YYDPRINTF(Args)
278 #endif /* !YYDEBUG */
281 yy::b4_name::parse ()
286 /* Initialize stack. */
287 state_stack_
= StateStack (0);
288 semantic_stack_
= SemanticStack (1);
289 location_stack_
= LocationStack (1);
291 /* Reserve initial space. The C parser needed that, but is it really
293 state_stack_
.reserve (initdepth_
);
294 semantic_stack_
.reserve (initdepth_
);
295 location_stack_
.reserve (initdepth_
);
301 location
= initlocation_
;
303 YYDPRINTF ((stderr
, "Starting parse\n"));
307 state_stack_
.push (state_
);
308 YYDPRINTF ((stderr
, "Entering state %d\n", state_
));
314 /* Try to take a decision without lookahead. */
315 n_
= pact_
[[state_]];
319 /* Read a lookahead token. */
320 if (looka_
== empty_
)
322 YYDPRINTF ((stderr
, "Reading a token: "));
326 /* Convert token to internal form. */
331 YYDPRINTF ((stderr
, "Now at end of input.\n"));
335 ilooka_
= translate_ (looka_
);
339 YYFPRINTF (stderr
, "Next token is %d (%s", looka_
, name_
[[ilooka_]]);
341 YYFPRINTF (stderr
, ")\n");
347 if (n_
< 0 || n_
> last_
|| check_
[[n_]] != ilooka_
)
350 /* Reduce or error. */
369 /* Shift the lookahead token. */
370 YYDPRINTF ((stderr
, "Shifting token %d (%s), ", looka_
, name_
[[ilooka_]]));
372 /* Discard the token being shifted unless it is eof. */
376 semantic_stack_
.push (value
);
377 location_stack_
.push (location
);
379 /* Count tokens shifted since error; after three, turn off error
387 /* Default action. */
389 n_
= defact_
[[state_]];
399 yyval
= semantic_stack_
[[1 - len_
]];
400 yyloc
= location_stack_
[[1 - len_
]];
404 yyval
= semantic_stack_
[[0]];
405 yyloc
= location_stack_
[[0]];
411 YYFPRINTF (stderr
, "Reducing via rule %d (line %d), ", n_
- 1, rline_
[[n_]]);
412 for (unsigned i
= prhs_
[[n_]];
414 YYFPRINTF (stderr
, "%s ", name_
[[rhs_
[i
]]]);
415 YYFPRINTF (stderr
, "-> %s\n", name_
[[r1_
[n_
]]]);
421 Slice
< LocationType
, LocationStack
> slice (location_stack_
, len_
);
422 YYLLOC_DEFAULT (yyloc
, slice
, len_
);
426 SemanticStack
& yyvsp (semantic_stack_
);
427 LocationStack
& yylsp (location_stack_
);
435 state_stack_
.pop (len_
);
436 semantic_stack_
.pop (len_
);
437 location_stack_
.pop (len_
);
442 YYFPRINTF (stderr
, "state stack now");
443 for (StateStack::ConstIterator i
= state_stack_
.begin ();
444 i
!= state_stack_
.end (); ++i
)
445 YYFPRINTF (stderr
, " %d", *i
);
446 YYFPRINTF (stderr
, "\n");
450 semantic_stack_
.push (yyval
);
451 location_stack_
.push (yyloc
);
453 /* Shift the result of the reduction. */
455 state_
= pgoto_
[[n_
- ntokens_
]] + state_stack_
[[0]];
456 if (state_
>= 0 && state_
<= last_
&& check_
[[state_]] == state_stack_
[[0]])
457 state_
= table_
[[state_]];
459 state_
= defgoto_
[[n_
- ntokens_
]];
462 /* Report and recover from errors. This is very incomplete. */
464 /* If not already recovering from an error, report this error. */
470 n_
= pact_
[[state_]];
471 if (n_
> flag_
&& n_
< last_
)
473 message
= "parse error, unexpected ";
474 message
+= name_
[[ilooka_]];
477 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
478 if (check_
[[x
+ n_
]] == x
)
483 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
484 if (check_
[[x
+ n_
]] == x
)
486 message
+= (!count
++) ? ", expecting " : " or ";
487 message
+= name_
[[x]];
494 message
= "parse error";
499 /* Error raised explicitly by an action. */
503 /* If just tried and failed to reuse lookahead token after an
504 error, discard it. */
506 /* Return failure if at end of input. */
509 YYDPRINTF ((stderr
, "Discarding token %d (%s).\n", looka_
, name_
[[ilooka_]]));
513 /* Else will try to reuse lookahead token after shifting the error
519 /* Pop the current state because it cannot handle the error token. */
522 if (!state_stack_
.height ())
524 state_
= (state_stack_
.pop (), state_stack_
[[0]]);
525 semantic_stack_
.pop ();
526 location_stack_
.pop ();;
531 YYFPRINTF (stderr
, "Error: state stack now");
532 for (StateStack::ConstIterator i
= state_stack_
.begin ();
533 i
!= state_stack_
.end (); ++i
)
534 YYFPRINTF (stderr
, " %d", *i
);
535 YYFPRINTF (stderr
, "\n");
540 n_
= pact_
[[state_]];
545 if (n_
< 0 || n_
> last_
|| check_
[[n_]] != terror_
)
562 YYDPRINTF ((stderr
, "Shifting error token, "));
564 semantic_stack_
.push (value
);
565 location_stack_
.push (location
);
583 looka_
= yylex (&value
, &location
);
585 looka_
= yylex (&value
);
589 /* YYPACT[[STATE-NUM]] -- Index in YYTABLE of the portion describing
592 yy::b4_name::pact_
[[]] =
597 /* YYDEFACT[[S]] -- default rule to reduce with in state S when YYTABLE
598 doesn't specify something else to do. Zero means the default is an
601 yy::b4_name::defact_
[[]] =
606 /* YYPGOTO[[NTERM-NUM]]. */
608 yy::b4_name::pgoto_
[[]] =
613 /* YYDEFGOTO[[NTERM-NUM]]. */
615 yy::b4_name::defgoto_
[[]] =
620 /* YYTABLE[[YYPACT[STATE-NUM]]]. What to do in state STATE-NUM. If
621 positive, shift that token. If negative, reduce the rule which
622 number is the opposite. If zero, do what YYDEFACT says. */
624 yy::b4_name::table_
[[]] =
631 yy::b4_name::check_
[[]] =
636 /* YYR1[[YYN]] -- Symbol number of symbol that rule YYN derives. */
638 yy::b4_name::r1_
[[]] =
643 /* YYR2[[YYN]] -- Number of symbols composing right hand side of rule YYN. */
645 yy::b4_name::r2_
[[]] =
650 #if YYDEBUG || YYERROR_VERBOSE
651 /* YYTNAME[[SYMBOL-NUM]] -- String name of the symbol SYMBOL-NUM.
652 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
654 const yy::b4_name::name_
[[]] =
661 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
663 yy::b4_name::rhs_
[[]] =
668 /* YYPRHS[[YYN]] -- Index of the first RHS symbol of rule number YYN in
671 yy::b4_name::prhs_
[[]] =
676 /* YYRLINE[[YYN]] -- source line where rule number YYN was defined. */
678 yy::b4_name::rline_
[[]] =
684 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
686 yy::b4_name::translate_ (int token
)
694 return ((unsigned)(token
) <= maxtok_
? translate_
[[token]] : nsym_
);
697 const int yy::b4_name::eof_
= 0;
698 const int yy::b4_name::last_
= b4_last
;
699 const int yy::b4_name::flag_
= b4_flag
;
700 const int yy::b4_name::nnts_
= b4_nnts
;
701 const int yy::b4_name::nsym_
= b4_nsym
;
702 const int yy::b4_name::empty_
= -2;
703 const int yy::b4_name::final_
= b4_final
;
704 const int yy::b4_name::terror_
= 1;
705 const int yy::b4_name::errcode_
= 256;
706 const int yy::b4_name::ntokens_
= b4_ntokens
;
707 const int yy::b4_name::initdepth_
= b4_initdepth
;
709 const unsigned yy::b4_name::maxtok_
= b4_maxtok
;
716 #ifndef BISON_STACK_HH
717 # define BISON_STACK_HH
723 template < class T
, class S
= std::vector
< T
> >
728 typedef typename
S::iterator Iterator
;
729 typedef typename
S::const_iterator ConstIterator
;
735 Stack (unsigned n
) : seq_ (n
)
741 operator [[]] (int index
)
743 return seq_
[[height () - 1 + index
]];
748 operator [[]] (int index
) const
750 return seq_
[[height () - 1 + index
]];
782 inline ConstIterator
begin () const { return seq_
.begin (); }
783 inline ConstIterator
end () const { return seq_
.end (); }
790 template < class T
, class S
= Stack
< T
> >
795 Slice (const S
& stack
,
796 unsigned range
) : stack_ (stack
),
803 operator [[]] (unsigned index
) const
805 return stack_
[[index
- range_
]];
815 #endif // not BISON_STACK_HH
817 #output "location.hh"
820 #ifndef BISON_LOCATION_HH
821 # define BISON_LOCATION_HH
838 #endif // not BISON_LOCATION_HH