]> git.saurik.com Git - bison.git/blame - data/bison.c++
* data/bison.c++ (yy::b4_name::error_): New method, replaces yyerror in
[bison.git] / data / bison.c++
CommitLineData
50997c6e 1#output "b4_output_prefix[]b4_output_infix[]-class.hh"
2b548aa6
RA
2/* -*- C++ -*- */
3
4/* A Bison parser, made from %%filename,
5 by GNU bison %%version. */
6
7/* Skeleton output parser for bison,
50997c6e 8 Copyright 1984, 1989, 1990, 2000, 2001 Free Software Foundation, Inc.
2b548aa6
RA
9
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)
13 any later version.
14
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.
19
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. */
24
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. */
29
30#include "stack.hh"
2b548aa6
RA
31#include "location.hh"
32
50997c6e
RA
33b4_prologue
34
35// FIXME: This should be defined in traits, not here.
36typedef b4_stype yystype;
37
2b548aa6
RA
38namespace yy
39{
3f3eed27
AD
40 class b4_name;
41
2b548aa6
RA
42 template < typename P >
43 struct Traits
44 {
45 };
46
47 template < >
3f3eed27 48 struct Traits< b4_name >
2b548aa6 49 {
50997c6e
RA
50 typedef int StateType;
51 typedef yystype SemanticType;
52 typedef b4_ltype LocationType;
2b548aa6
RA
53 };
54}
55
2b548aa6
RA
56namespace yy
57{
3f3eed27 58 class b4_name
2b548aa6
RA
59 {
60 public:
3f3eed27 61
50997c6e 62 typedef Traits< b4_name >::StateType StateType;
3f3eed27
AD
63 typedef Traits< b4_name >::SemanticType SemanticType;
64 typedef Traits< b4_name >::LocationType LocationType;
2b548aa6
RA
65
66 typedef Stack< StateType > StateStack;
67 typedef Stack< SemanticType > SemanticStack;
68 typedef Stack< LocationType > LocationStack;
69
50997c6e
RA
70 b4_name (bool debug) : debug_ (debug)
71 {
72 looka = empty_;
73 }
74
75 virtual ~b4_name ()
2b548aa6 76 {
2b548aa6
RA
77 }
78
79 virtual int parse ();
80
81 private:
3f3eed27 82
4bb2bc3f
RA
83 virtual void error_ ();
84
2b548aa6 85 /* Call to lexical analyser. */
4bb2bc3f
RA
86 virtual
87 void
88 lex ()
89 {
50997c6e 90 looka = yylex (&value, &location);
2b548aa6
RA
91 }
92
93 /* Stacks. */
94 StateStack state_stack;
95 SemanticStack semantic_stack;
96 LocationStack location_stack;
97
98 /* Tables. */
3f3eed27
AD
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_[[]];
3f3eed27
AD
105 static const short r1_[[]];
106 static const short r2_[[]];
107 static const char* const name_[[]];
2b548aa6
RA
108
109 /* More tables, for debugging. */
50997c6e 110 /* FIXME: These tables should not be printed when not in debug
2b548aa6 111 mode. %%ifdef? */
3f3eed27
AD
112 static const short rhs_[[]];
113 static const short prhs_[[]];
114 static const short rline_[[]];
2b548aa6
RA
115
116 /* Even more tables. */
117 static inline char translate (int token);
118
119 /* Eof and empty. */
50997c6e
RA
120 static const int eof_;
121 static const int empty_;
122 static const int ntokens_;
2b548aa6
RA
123
124 /* State. */
125 int n;
126 int len;
50997c6e 127 int debug_;
2b548aa6 128 int state;
4bb2bc3f 129
2b548aa6
RA
130 /* Lookahead. */
131 int looka;
132 int ilooka;
4bb2bc3f
RA
133
134 /* Message. */
135 std::string message;
136
2b548aa6
RA
137 /* @$ and $$. */
138 SemanticType value;
139 LocationType location;
140 };
141}
142
3f3eed27 143#output "b4_output_prefix[]b4_output_infix[].cc"
50997c6e
RA
144#include "b4_output_prefix[]b4_output_infix-class.hh"
145
146/* Enabling traces. */
147#ifndef YYDEBUG
148# define YYDEBUG b4_debug
149#endif
2b548aa6
RA
150
151/* Enable debugging if requested. */
50997c6e 152#if YYDEBUG
2b548aa6
RA
153
154# include <cstdio>
155# define YYFPRINTF std::fprintf
156
157# define YYDPRINTF(Args) \
158do { \
50997c6e 159 if (debug_) \
2b548aa6
RA
160 YYFPRINTF Args; \
161} while (0)
50997c6e
RA
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.
165 */
2b548aa6
RA
166int yydebug;
167#else /* !YYDEBUG */
168# define YYDPRINTF(Args)
169#endif /* !YYDEBUG */
170
171/* Tokens. */
3f3eed27 172b4_tokendef
2b548aa6
RA
173
174int
3f3eed27 175yy::b4_name::parse ()
2b548aa6 176{
4bb2bc3f
RA
177 int nerrs = 0;
178 int errstatus = 0;
179
2b548aa6
RA
180 /* Initialize stack. */
181 state_stack = StateStack (0);
182 semantic_stack = SemanticStack (1);
183 location_stack = LocationStack (1);
184
185 /* Reserve initial space. The C parser needed that, but is it really
186 useful here? */
3f3eed27
AD
187 state_stack.reserve (b4_initdepth);
188 semantic_stack.reserve (b4_initdepth);
189 location_stack.reserve (b4_initdepth);
2b548aa6
RA
190
191 /* Start. */
192 state = 0;
193 YYDPRINTF ((stderr, "Starting parse\n"));
194
195 /* New state. */
196 yynewstate:
197 state_stack.push (state);
198 YYDPRINTF ((stderr, "Entering state %d\n", state));
50997c6e 199 goto yybackup;
2b548aa6
RA
200
201 /* Backup. */
202 yybackup:
203
204 /* Try to take a decision without lookahead. */
3f3eed27
AD
205 n = pact_[[state]];
206 if (n == b4_flag)
2b548aa6
RA
207 goto yydefault;
208
209 /* Read a lookahead token. */
50997c6e 210 if (looka == empty_)
2b548aa6
RA
211 {
212 YYDPRINTF ((stderr, "Reading a token: "));
213 lex ();
214 }
215
216 /* Convert token to internal form. */
217 if (looka <= 0)
218 {
50997c6e 219 looka = eof_;
2b548aa6
RA
220 ilooka = 0;
221 YYDPRINTF ((stderr, "Now at end of input.\n"));
222 }
223 else
224 {
225 ilooka = translate (looka);
50997c6e
RA
226#if YYDEBUG
227 if (debug_)
228 {
229 YYFPRINTF (stderr, "Next token is %d (%s", looka, name_[[ilooka]]);
230 YYFPRINTF (stderr, ")\n");
231 }
2b548aa6
RA
232#endif
233 }
234
235 n += ilooka;
3f3eed27 236 if (n < 0 || n > b4_last || check_[[n]] != ilooka)
2b548aa6
RA
237 goto yydefault;
238
239 /* Reduce or error. */
3f3eed27 240 n = table_[[n]];
2b548aa6
RA
241 if (n < 0)
242 {
3f3eed27 243 if (n == b4_flag)
2b548aa6
RA
244 goto yyerrlab;
245 else
246 {
247 n = -n;
248 goto yyreduce;
249 }
250 }
251 else if (n == 0)
252 goto yyerrlab;
50997c6e 253
2b548aa6 254 /* Accept? */
3f3eed27 255 if (n == b4_final)
2b548aa6
RA
256 goto yyacceptlab;
257
258 /* Shift the lookahead token. */
3f3eed27 259 YYDPRINTF ((stderr, "Shifting token %d (%s), ", looka, name_[[ilooka]]));
2b548aa6
RA
260
261 /* Discard the token being shifted unless it is eof. */
50997c6e
RA
262 if (looka != eof_)
263 looka = empty_;
2b548aa6
RA
264
265 semantic_stack.push (value);
266 location_stack.push (location);
267 state = n;
268 goto yynewstate;
269
270 /* Default action. */
271 yydefault:
3f3eed27 272 n = defact_[[state]];
2b548aa6
RA
273 if (n == 0)
274 goto yyerrlab;
50997c6e 275 goto yyreduce;
2b548aa6
RA
276
277 /* Reduce. */
278 yyreduce:
3f3eed27 279 len = r2_[[n]];
50997c6e
RA
280 if (len)
281 {
282 value = semantic_stack[[1 - len]];
283 location = location_stack[[1 - len]];
284 }
285 else
286 {
287 // FIXME: This is truly ugly.
288 value = semantic_stack[[0]];
289 location = location_stack[[0]];
290 }
2b548aa6 291
50997c6e
RA
292#if YYDEBUG
293 if (debug_)
2b548aa6 294 {
3f3eed27
AD
295 YYFPRINTF (stderr, "Reducing via rule %d (line %d), ", n - 1, rline_[[n]]);
296 for (unsigned i = prhs_[[n]];
297 rhs_[[i]] >= 0; ++i)
298 YYFPRINTF (stderr, "%s ", name_[[rhs_[i]]]);
299 YYFPRINTF (stderr, "-> %s\n", name_[[r1_[n]]]);
2b548aa6
RA
300 }
301#endif
50997c6e 302
2b548aa6
RA
303 {
304 SemanticType& yyval (value);
50997c6e 305 LocationType& yyloc (location);
2b548aa6 306 SemanticStack& yyvsp (semantic_stack);
50997c6e 307 LocationStack& yylsp (location_stack);
2b548aa6
RA
308
309 switch (n)
310 {
3f3eed27 311 b4_actions
2b548aa6
RA
312 }
313 }
50997c6e 314
2b548aa6
RA
315 state_stack.pop (len);
316 semantic_stack.pop (len);
317 location_stack.pop (len);
318
50997c6e
RA
319#if YYDEBUG
320 if (debug_)
2b548aa6
RA
321 {
322 YYFPRINTF (stderr, "state stack now");
50997c6e 323 for (StateStack::ConstIterator i = state_stack.begin ();
2b548aa6
RA
324 i != state_stack.end (); ++i)
325 YYFPRINTF (stderr, " %d", *i);
326 YYFPRINTF (stderr, "\n");
327 }
328#endif
50997c6e 329
2b548aa6
RA
330 semantic_stack.push (value);
331 location_stack.push (location);
332
333 /* Shift the result of the reduction. */
3f3eed27 334 n = r1_[[n]];
50997c6e 335 state = pgoto_[[n - ntokens_]] + state_stack[[0]];
3f3eed27
AD
336 if (state >= 0 && state <= b4_last && check_[[state]] == state_stack[[0]])
337 state = table_[[state]];
2b548aa6 338 else
50997c6e 339 state = defgoto_[[n - ntokens_]];
2b548aa6
RA
340 goto yynewstate;
341
342 /* Report and recover from errors. This is very incomplete. */
343 yyerrlab:
4bb2bc3f
RA
344 /* If not already recovering from an error, report this error. */
345 if (!errstatus)
346 {
347 ++nerrs;
348
349 // FIXME: Should be #if YYERROR_VERBOSE from here...
350 n = pact_[[state]];
351 if (n > b4_flag && n < b4_last)
352 {
353 message = "parse error, unexpected ";
354 message += name_[[ilooka]];
355 {
356 int count = 0;
357 for (int x = (n < 0 ? -n : 0); x < b4_ntokens + b4_nnts; ++x)
358 if (check_[[x + n]] == x)
359 ++count;
360 if (count < 5)
361 {
362 count = 0;
363 for (int x = (n < 0 ? -n : 0); x < b4_ntokens + b4_nnts; ++x)
364 if (check_[[x + n]] == x)
365 {
366 message += (!count++) ? ", expecting " : " or ";
367 message += name_[[x]];
368 }
369 }
370 }
371 }
372 else
373 // FIXME: to there...
374 message = "parse error";
375 }
376 error_ ();
2b548aa6 377 return 1;
50997c6e 378
2b548aa6
RA
379 /* Accept. */
380 yyacceptlab:
381 return 0;
382}
383
6b45a3ca 384/* YYPACT[[STATE-NUM]] -- Index in YYTABLE of the portion describing
2b548aa6 385 STATE-NUM. */
50997c6e 386const short
3f3eed27 387yy::b4_name::pact_[[]] =
2b548aa6 388{
3f3eed27 389 b4_pact
2b548aa6
RA
390};
391
6b45a3ca 392/* YYDEFACT[[S]] -- default rule to reduce with in state S when YYTABLE
2b548aa6
RA
393 doesn't specify something else to do. Zero means the default is an
394 error. */
50997c6e 395const short
3f3eed27 396yy::b4_name::defact_[[]] =
2b548aa6 397{
3f3eed27 398 b4_defact
2b548aa6
RA
399};
400
6b45a3ca 401/* YYPGOTO[[NTERM-NUM]]. */
50997c6e 402const short
3f3eed27 403yy::b4_name::pgoto_[[]] =
2b548aa6 404{
3f3eed27 405 b4_pgoto
2b548aa6
RA
406};
407
6b45a3ca 408/* YYDEFGOTO[[NTERM-NUM]]. */
50997c6e 409const short
3f3eed27 410yy::b4_name::defgoto_[[]] =
2b548aa6 411{
3f3eed27 412 b4_defgoto
2b548aa6
RA
413};
414
6b45a3ca 415/* YYTABLE[[YYPACT[STATE-NUM]]]. What to do in state STATE-NUM. If
2b548aa6
RA
416 positive, shift that token. If negative, reduce the rule which
417 number is the opposite. If zero, do what YYDEFACT says. */
50997c6e 418const short
3f3eed27 419yy::b4_name::table_[[]] =
2b548aa6 420{
3f3eed27 421 b4_table
2b548aa6
RA
422};
423
424/* YYCHECK. */
50997c6e 425const short
3f3eed27 426yy::b4_name::check_[[]] =
2b548aa6 427{
3f3eed27 428 b4_check
2b548aa6
RA
429};
430
6b45a3ca 431/* YYRLINE[[YYN]] -- source line where rule number YYN was defined. */
2b548aa6 432const short
50997c6e 433yy::b4_name::rline_[[]] =
2b548aa6 434{
50997c6e 435 b4_rline
2b548aa6
RA
436};
437
6b45a3ca 438/* YYR1[[YYN]] -- Symbol number of symbol that rule YYN derives. */
50997c6e 439const short
3f3eed27 440yy::b4_name::r1_[[]] =
2b548aa6 441{
3f3eed27 442 b4_r1
2b548aa6
RA
443};
444
6b45a3ca 445/* YYR2[[YYN]] -- Number of symbols composing right hand side of rule YYN. */
50997c6e 446const short
3f3eed27 447yy::b4_name::r2_[[]] =
2b548aa6 448{
3f3eed27 449 b4_r2
2b548aa6
RA
450};
451
6b45a3ca 452/* YYTNAME[[SYMBOL-NUM]] -- String name of the symbol SYMBOL-NUM.
2b548aa6
RA
453 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
454const char*
3f3eed27 455const yy::b4_name::name_[[]] =
2b548aa6 456{
3f3eed27 457 b4_tname
2b548aa6
RA
458};
459
460/* YYRHS -- A `-1'-separated list of the rules' RHS. */
50997c6e 461const short
3f3eed27 462yy::b4_name::rhs_[[]] =
2b548aa6 463{
3f3eed27 464 b4_rhs
2b548aa6
RA
465};
466
6b45a3ca 467/* YYPRHS[[YYN]] -- Index of the first RHS symbol of rule number YYN in
2b548aa6 468 YYRHS. */
50997c6e 469const short
3f3eed27 470yy::b4_name::prhs_[[]] =
2b548aa6 471{
3f3eed27 472 b4_prhs
2b548aa6
RA
473};
474
2b548aa6
RA
475/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
476char
3f3eed27 477yy::b4_name::translate (int token)
2b548aa6 478{
50997c6e
RA
479 static
480 const char
3f3eed27 481 translate_[[]] =
2b548aa6 482 {
3f3eed27 483 b4_translate
2b548aa6 484 };
3f3eed27 485 return ((unsigned)(token) <= b4_maxtok ? translate_[[token]] : b4_nsym);
2b548aa6
RA
486}
487
50997c6e
RA
488const int yy::b4_name::eof_ = 0;
489const int yy::b4_name::empty_ = -2;
490const int yy::b4_name::ntokens_ = b4_ntokens;
2b548aa6 491
3f3eed27 492b4_epilogue
2b548aa6 493
3f3eed27 494#output "stack.hh"
2b548aa6
RA
495#ifndef BISON_STACK_HH
496# define BISON_STACK_HH
497
498#include <vector>
499
500namespace yy
501{
502 template < class T, class S = std::vector< T > >
503 class Stack
504 {
505 public:
506
507 typedef typename S::iterator Iterator;
508 typedef typename S::const_iterator ConstIterator;
509
510 Stack () : seq_ ()
511 {
512 }
513
514 Stack (unsigned n) : seq_ (n)
515 {
516 }
517
518 inline
519 T&
3f3eed27 520 operator [[]] (int index)
2b548aa6 521 {
3f3eed27 522 return seq_[[seq_.size () - 1 + index]];
2b548aa6
RA
523 }
524
525 inline
526 const T&
3f3eed27 527 operator [[]] (int index) const
2b548aa6 528 {
3f3eed27 529 return seq_[[seq_.size () - 1 + index]];
2b548aa6
RA
530 }
531
532 inline
533 void
534 push (const T& t)
535 {
536 seq_.push_back (t);
537 }
538
539 inline
540 void
541 pop (unsigned n = 1)
542 {
543 for (; n; --n)
544 seq_.pop_back ();
545 }
50997c6e 546
2b548aa6
RA
547 inline
548 void
549 reserve (unsigned n)
550 {
551 seq_.reserve (n);
552 }
553
554 inline ConstIterator begin () const { return seq_.begin (); }
555 inline ConstIterator end () const { return seq_.end (); }
556
557 private:
558
559 S seq_;
560 };
561}
562
563#endif // not BISON_STACK_HH
564
3f3eed27 565#output "location.hh"
2b548aa6
RA
566#ifndef BISON_LOCATION_HH
567# define BISON_LOCATION_HH
568
569namespace yy
570{
571 struct Position
572 {
573 int line;
574 int column;
575 };
576
577 struct Location
578 {
579 Position first;
580 Position last;
581 };
582}
583
584#endif // not BISON_LOCATION_HH
50997c6e
RA
585
586m4_if(b4_defines_flag, 0, [],
587[#output "b4_output_header_name"
588#ifndef b4_header_guard
589# define b4_header_guard
590
591b4_tokendef
592
593#ifndef YYSTYPE
594typedef b4_stype
595yystype;
596# define YYSTYPE yystype
597#endif
598
599m4_if(b4_pure, [0],
600[extern YYSTYPE b4_prefix[]lval;])
601
602m4_if(b4_locations_flag, [0], [],
603[#ifndef YYLTYPE
604typedef struct yyltype
605{
606 int first_line;
607 int first_column;
608 int last_line;
609 int last_column;
610} yyltype;
611# define YYLTYPE yyltype
612#endif
613
614m4_if(b4_pure, [0],
615[extern YYLTYPE b4_prefix[]lloc;])
616])
617#endif /* not b4_header_guard */
618])