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 terror_
;
123 static const int errcode_
;
124 static const int ntokens_
;
141 LocationType location
;
145 #output "b4_output_prefix[]b4_output_infix[].cc"
146 #include "b4_output_prefix[]b4_output_infix-class.hh"
148 /* Enabling traces. */
150 # define YYDEBUG b4_debug
153 /* Enable debugging if requested. */
157 # define YYFPRINTF std::fprintf
159 # define YYDPRINTF(Args) \
164 /* Nonzero means print parse trace. [The following comment makes no
165 sense to me. Could someone clarify it? --akim] Since this is
166 uninitialized, it does not stop multiple parsers from coexisting.
170 # define YYDPRINTF(Args)
171 #endif /* !YYDEBUG */
177 yy::b4_name::parse ()
182 /* Initialize stack. */
183 state_stack
= StateStack (0);
184 semantic_stack
= SemanticStack (1);
185 location_stack
= LocationStack (1);
187 /* Reserve initial space. The C parser needed that, but is it really
189 state_stack
.reserve (b4_initdepth
);
190 semantic_stack
.reserve (b4_initdepth
);
191 location_stack
.reserve (b4_initdepth
);
195 YYDPRINTF ((stderr
, "Starting parse\n"));
199 state_stack
.push (state
);
200 YYDPRINTF ((stderr
, "Entering state %d\n", state
));
206 /* Try to take a decision without lookahead. */
211 /* Read a lookahead token. */
214 YYDPRINTF ((stderr
, "Reading a token: "));
218 /* Convert token to internal form. */
223 YYDPRINTF ((stderr
, "Now at end of input.\n"));
227 ilooka
= translate (looka
);
231 YYFPRINTF (stderr
, "Next token is %d (%s", looka
, name_
[[ilooka]]);
232 YYFPRINTF (stderr
, ")\n");
238 if (n
< 0 || n
> b4_last
|| check_
[[n]] != ilooka
)
241 /* Reduce or error. */
260 /* Shift the lookahead token. */
261 YYDPRINTF ((stderr
, "Shifting token %d (%s), ", looka
, name_
[[ilooka]]));
263 /* Discard the token being shifted unless it is eof. */
267 semantic_stack
.push (value
);
268 location_stack
.push (location
);
272 /* Default action. */
274 n
= defact_
[[state]];
284 value
= semantic_stack
[[1 - len
]];
285 location
= location_stack
[[1 - len
]];
289 // FIXME: This is truly ugly.
290 value
= semantic_stack
[[0]];
291 location
= location_stack
[[0]];
297 YYFPRINTF (stderr
, "Reducing via rule %d (line %d), ", n
- 1, rline_
[[n]]);
298 for (unsigned i
= prhs_
[[n]];
300 YYFPRINTF (stderr
, "%s ", name_
[[rhs_
[i
]]]);
301 YYFPRINTF (stderr
, "-> %s\n", name_
[[r1_
[n
]]]);
306 SemanticType
& yyval (value
);
307 LocationType
& yyloc (location
);
308 SemanticStack
& yyvsp (semantic_stack
);
309 LocationStack
& yylsp (location_stack
);
317 state_stack
.pop (len
);
318 semantic_stack
.pop (len
);
319 location_stack
.pop (len
);
324 YYFPRINTF (stderr
, "state stack now");
325 for (StateStack::ConstIterator i
= state_stack
.begin ();
326 i
!= state_stack
.end (); ++i
)
327 YYFPRINTF (stderr
, " %d", *i
);
328 YYFPRINTF (stderr
, "\n");
332 semantic_stack
.push (value
);
333 location_stack
.push (location
);
335 /* Shift the result of the reduction. */
337 state
= pgoto_
[[n
- ntokens_
]] + state_stack
[[0]];
338 if (state
>= 0 && state
<= b4_last
&& check_
[[state]] == state_stack
[[0]])
339 state
= table_
[[state]];
341 state
= defgoto_
[[n
- ntokens_
]];
344 /* Report and recover from errors. This is very incomplete. */
346 /* If not already recovering from an error, report this error. */
351 // FIXME: Should be #if YYERROR_VERBOSE from here...
353 if (n
> b4_flag
&& n
< b4_last
)
355 message
= "parse error, unexpected ";
356 message
+= name_
[[ilooka]];
359 for (int x
= (n
< 0 ? -n
: 0); x
< b4_ntokens
+ b4_nnts
; ++x
)
360 if (check_
[[x
+ n
]] == x
)
365 for (int x
= (n
< 0 ? -n
: 0); x
< b4_ntokens
+ b4_nnts
; ++x
)
366 if (check_
[[x
+ n
]] == x
)
368 message
+= (!count
++) ? ", expecting " : " or ";
369 message
+= name_
[[x]];
375 // FIXME: to there...
376 message
= "parse error";
381 /* Error raised explicitly by an action. */
385 /* If just tried and failed to reuse lookahead token after an
386 error, discard it. */
388 /* Return failure if at end of input. */
391 YYDPRINTF ((stderr
, "Discarding token %d (%s).\n", looka
, name_
[[ilooka]]));
395 /* Else will try to reuse lookahead token after shifting the error
401 /* Pop the current state because it cannot handle the error token. */
404 if (!state_stack
.height ())
406 state
= (state_stack
.pop (), state_stack
[[0]]);
407 semantic_stack
.pop ();
408 location_stack
.pop ();;
413 YYFPRINTF (stderr
, "Error: state stack now");
414 for (StateStack::ConstIterator i
= state_stack
.begin ();
415 i
!= state_stack
.end (); ++i
)
416 YYFPRINTF (stderr
, " %d", *i
);
417 YYFPRINTF (stderr
, "\n");
427 if (n
< 0 || n
> b4_last
|| check_
[[n]] != terror_
)
444 YYDPRINTF ((stderr
, "Shifting error token, "));
446 semantic_stack
.push (value
);
447 location_stack
.push (location
);
461 /* YYPACT[[STATE-NUM]] -- Index in YYTABLE of the portion describing
464 yy::b4_name::pact_
[[]] =
469 /* YYDEFACT[[S]] -- default rule to reduce with in state S when YYTABLE
470 doesn't specify something else to do. Zero means the default is an
473 yy::b4_name::defact_
[[]] =
478 /* YYPGOTO[[NTERM-NUM]]. */
480 yy::b4_name::pgoto_
[[]] =
485 /* YYDEFGOTO[[NTERM-NUM]]. */
487 yy::b4_name::defgoto_
[[]] =
492 /* YYTABLE[[YYPACT[STATE-NUM]]]. What to do in state STATE-NUM. If
493 positive, shift that token. If negative, reduce the rule which
494 number is the opposite. If zero, do what YYDEFACT says. */
496 yy::b4_name::table_
[[]] =
503 yy::b4_name::check_
[[]] =
508 /* YYRLINE[[YYN]] -- source line where rule number YYN was defined. */
510 yy::b4_name::rline_
[[]] =
515 /* YYR1[[YYN]] -- Symbol number of symbol that rule YYN derives. */
517 yy::b4_name::r1_
[[]] =
522 /* YYR2[[YYN]] -- Number of symbols composing right hand side of rule YYN. */
524 yy::b4_name::r2_
[[]] =
529 /* YYTNAME[[SYMBOL-NUM]] -- String name of the symbol SYMBOL-NUM.
530 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
532 const yy::b4_name::name_
[[]] =
537 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
539 yy::b4_name::rhs_
[[]] =
544 /* YYPRHS[[YYN]] -- Index of the first RHS symbol of rule number YYN in
547 yy::b4_name::prhs_
[[]] =
552 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
554 yy::b4_name::translate (int token
)
562 return ((unsigned)(token
) <= b4_maxtok
? translate_
[[token]] : b4_nsym
);
565 const int yy::b4_name::eof_
= 0;
566 const int yy::b4_name::empty_
= -2;
567 const int yy::b4_name::terror_
= 1;
568 const int yy::b4_name::errcode_
= 256;
569 const int yy::b4_name::ntokens_
= b4_ntokens
;
574 #ifndef BISON_STACK_HH
575 # define BISON_STACK_HH
581 template < class T
, class S
= std::vector
< T
> >
586 typedef typename
S::iterator Iterator
;
587 typedef typename
S::const_iterator ConstIterator
;
593 Stack (unsigned n
) : seq_ (n
)
599 operator [[]] (int index
)
601 return seq_
[[seq_
.size () - 1 + index
]];
606 operator [[]] (int index
) const
608 return seq_
[[seq_
.size () - 1 + index
]];
640 inline ConstIterator
begin () const { return seq_
.begin (); }
641 inline ConstIterator
end () const { return seq_
.end (); }
649 #endif // not BISON_STACK_HH
651 #output "location.hh"
652 #ifndef BISON_LOCATION_HH
653 # define BISON_LOCATION_HH
670 #endif // not BISON_LOCATION_HH
672 m4_if(b4_defines_flag
, 0, [],
673 [#output "b4_output_header_name"
674 #ifndef b4_header_guard
675 # define b4_header_guard
682 # define YYSTYPE yystype
686 [extern YYSTYPE b4_prefix
[]lval
;])
688 m4_if(b4_locations_flag
, [0], [],
690 typedef struct yyltype
697 # define YYLTYPE yyltype
701 [extern YYLTYPE b4_prefix
[]lloc
;])
703 #endif /* not b4_header_guard */