1 #output "b4_output_prefix[]b4_output_infix[]-class.hh"
4 /* A Bison parser, made from %%filename,
5 by GNU bison %%version. */
7 /* Skeleton output parser for bison,
8 Copyright 1984, 1989, 1990, 2000, 2001 Free Software Foundation, Inc.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
25 /* As a special exception, when this file is copied by Bison into a
26 Bison output file, you may use that output file without restriction.
27 This special exception was added by the Free Software Foundation
28 in version 1.24 of Bison. */
31 #include "location.hh"
35 // FIXME: This should be defined in traits, not here.
36 typedef b4_stype yystype
;
42 template < typename P
>
48 struct Traits
< b4_name
>
50 typedef int StateType
;
51 typedef yystype SemanticType
;
52 typedef b4_ltype LocationType
;
62 typedef Traits
< b4_name
>::StateType StateType
;
63 typedef Traits
< b4_name
>::SemanticType SemanticType
;
64 typedef Traits
< b4_name
>::LocationType LocationType
;
66 typedef Stack
< StateType
> StateStack
;
67 typedef Stack
< SemanticType
> SemanticStack
;
68 typedef Stack
< LocationType
> LocationStack
;
70 b4_name (bool debug
) : debug_ (debug
)
83 virtual void error_ ();
85 /* Call to lexical analyser. */
90 looka
= yylex (&value
, &location
);
94 StateStack state_stack
;
95 SemanticStack semantic_stack
;
96 LocationStack location_stack
;
99 static const short pact_
[[]];
100 static const short defact_
[[]];
101 static const short pgoto_
[[]];
102 static const short defgoto_
[[]];
103 static const short table_
[[]];
104 static const short check_
[[]];
105 static const short r1_
[[]];
106 static const short r2_
[[]];
107 static const char* const name_
[[]];
109 /* More tables, for debugging. */
110 /* FIXME: These tables should not be printed when not in debug
112 static const short rhs_
[[]];
113 static const short prhs_
[[]];
114 static const short rline_
[[]];
116 /* Even more tables. */
117 static inline char translate (int token
);
120 static const int eof_
;
121 static const int empty_
;
122 static const int ntokens_
;
139 LocationType location
;
143 #output "b4_output_prefix[]b4_output_infix[].cc"
144 #include "b4_output_prefix[]b4_output_infix-class.hh"
146 /* Enabling traces. */
148 # define YYDEBUG b4_debug
151 /* Enable debugging if requested. */
155 # define YYFPRINTF std::fprintf
157 # define YYDPRINTF(Args) \
162 /* Nonzero means print parse trace. [The following comment makes no
163 sense to me. Could someone clarify it? --akim] Since this is
164 uninitialized, it does not stop multiple parsers from coexisting.
168 # define YYDPRINTF(Args)
169 #endif /* !YYDEBUG */
175 yy::b4_name::parse ()
180 /* Initialize stack. */
181 state_stack
= StateStack (0);
182 semantic_stack
= SemanticStack (1);
183 location_stack
= LocationStack (1);
185 /* Reserve initial space. The C parser needed that, but is it really
187 state_stack
.reserve (b4_initdepth
);
188 semantic_stack
.reserve (b4_initdepth
);
189 location_stack
.reserve (b4_initdepth
);
193 YYDPRINTF ((stderr
, "Starting parse\n"));
197 state_stack
.push (state
);
198 YYDPRINTF ((stderr
, "Entering state %d\n", state
));
204 /* Try to take a decision without lookahead. */
209 /* Read a lookahead token. */
212 YYDPRINTF ((stderr
, "Reading a token: "));
216 /* Convert token to internal form. */
221 YYDPRINTF ((stderr
, "Now at end of input.\n"));
225 ilooka
= translate (looka
);
229 YYFPRINTF (stderr
, "Next token is %d (%s", looka
, name_
[[ilooka]]);
230 YYFPRINTF (stderr
, ")\n");
236 if (n
< 0 || n
> b4_last
|| check_
[[n]] != ilooka
)
239 /* Reduce or error. */
258 /* Shift the lookahead token. */
259 YYDPRINTF ((stderr
, "Shifting token %d (%s), ", looka
, name_
[[ilooka]]));
261 /* Discard the token being shifted unless it is eof. */
265 semantic_stack
.push (value
);
266 location_stack
.push (location
);
270 /* Default action. */
272 n
= defact_
[[state]];
282 value
= semantic_stack
[[1 - len
]];
283 location
= location_stack
[[1 - len
]];
287 // FIXME: This is truly ugly.
288 value
= semantic_stack
[[0]];
289 location
= location_stack
[[0]];
295 YYFPRINTF (stderr
, "Reducing via rule %d (line %d), ", n
- 1, rline_
[[n]]);
296 for (unsigned i
= prhs_
[[n]];
298 YYFPRINTF (stderr
, "%s ", name_
[[rhs_
[i
]]]);
299 YYFPRINTF (stderr
, "-> %s\n", name_
[[r1_
[n
]]]);
304 SemanticType
& yyval (value
);
305 LocationType
& yyloc (location
);
306 SemanticStack
& yyvsp (semantic_stack
);
307 LocationStack
& yylsp (location_stack
);
315 state_stack
.pop (len
);
316 semantic_stack
.pop (len
);
317 location_stack
.pop (len
);
322 YYFPRINTF (stderr
, "state stack now");
323 for (StateStack::ConstIterator i
= state_stack
.begin ();
324 i
!= state_stack
.end (); ++i
)
325 YYFPRINTF (stderr
, " %d", *i
);
326 YYFPRINTF (stderr
, "\n");
330 semantic_stack
.push (value
);
331 location_stack
.push (location
);
333 /* Shift the result of the reduction. */
335 state
= pgoto_
[[n
- ntokens_
]] + state_stack
[[0]];
336 if (state
>= 0 && state
<= b4_last
&& check_
[[state]] == state_stack
[[0]])
337 state
= table_
[[state]];
339 state
= defgoto_
[[n
- ntokens_
]];
342 /* Report and recover from errors. This is very incomplete. */
344 /* If not already recovering from an error, report this error. */
349 // FIXME: Should be #if YYERROR_VERBOSE from here...
351 if (n
> b4_flag
&& n
< b4_last
)
353 message
= "parse error, unexpected ";
354 message
+= name_
[[ilooka]];
357 for (int x
= (n
< 0 ? -n
: 0); x
< b4_ntokens
+ b4_nnts
; ++x
)
358 if (check_
[[x
+ n
]] == x
)
363 for (int x
= (n
< 0 ? -n
: 0); x
< b4_ntokens
+ b4_nnts
; ++x
)
364 if (check_
[[x
+ n
]] == x
)
366 message
+= (!count
++) ? ", expecting " : " or ";
367 message
+= name_
[[x]];
373 // FIXME: to there...
374 message
= "parse error";
384 /* YYPACT[[STATE-NUM]] -- Index in YYTABLE of the portion describing
387 yy::b4_name::pact_
[[]] =
392 /* YYDEFACT[[S]] -- default rule to reduce with in state S when YYTABLE
393 doesn't specify something else to do. Zero means the default is an
396 yy::b4_name::defact_
[[]] =
401 /* YYPGOTO[[NTERM-NUM]]. */
403 yy::b4_name::pgoto_
[[]] =
408 /* YYDEFGOTO[[NTERM-NUM]]. */
410 yy::b4_name::defgoto_
[[]] =
415 /* YYTABLE[[YYPACT[STATE-NUM]]]. What to do in state STATE-NUM. If
416 positive, shift that token. If negative, reduce the rule which
417 number is the opposite. If zero, do what YYDEFACT says. */
419 yy::b4_name::table_
[[]] =
426 yy::b4_name::check_
[[]] =
431 /* YYRLINE[[YYN]] -- source line where rule number YYN was defined. */
433 yy::b4_name::rline_
[[]] =
438 /* YYR1[[YYN]] -- Symbol number of symbol that rule YYN derives. */
440 yy::b4_name::r1_
[[]] =
445 /* YYR2[[YYN]] -- Number of symbols composing right hand side of rule YYN. */
447 yy::b4_name::r2_
[[]] =
452 /* YYTNAME[[SYMBOL-NUM]] -- String name of the symbol SYMBOL-NUM.
453 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
455 const yy::b4_name::name_
[[]] =
460 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
462 yy::b4_name::rhs_
[[]] =
467 /* YYPRHS[[YYN]] -- Index of the first RHS symbol of rule number YYN in
470 yy::b4_name::prhs_
[[]] =
475 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
477 yy::b4_name::translate (int token
)
485 return ((unsigned)(token
) <= b4_maxtok
? translate_
[[token]] : b4_nsym
);
488 const int yy::b4_name::eof_
= 0;
489 const int yy::b4_name::empty_
= -2;
490 const int yy::b4_name::ntokens_
= b4_ntokens
;
495 #ifndef BISON_STACK_HH
496 # define BISON_STACK_HH
502 template < class T
, class S
= std::vector
< T
> >
507 typedef typename
S::iterator Iterator
;
508 typedef typename
S::const_iterator ConstIterator
;
514 Stack (unsigned n
) : seq_ (n
)
520 operator [[]] (int index
)
522 return seq_
[[seq_
.size () - 1 + index
]];
527 operator [[]] (int index
) const
529 return seq_
[[seq_
.size () - 1 + index
]];
554 inline ConstIterator
begin () const { return seq_
.begin (); }
555 inline ConstIterator
end () const { return seq_
.end (); }
563 #endif // not BISON_STACK_HH
565 #output "location.hh"
566 #ifndef BISON_LOCATION_HH
567 # define BISON_LOCATION_HH
584 #endif // not BISON_LOCATION_HH
586 m4_if(b4_defines_flag
, 0, [],
587 [#output "b4_output_header_name"
588 #ifndef b4_header_guard
589 # define b4_header_guard
596 # define YYSTYPE yystype
600 [extern YYSTYPE b4_prefix
[]lval
;])
602 m4_if(b4_locations_flag
, [0], [],
604 typedef struct yyltype
611 # define YYLTYPE yyltype
615 [extern YYLTYPE b4_prefix
[]lloc
;])
617 #endif /* not b4_header_guard */