]> git.saurik.com Git - bison.git/blame - data/lalr1.cc
* config/announce-gen, Makefile.cfg: New.
[bison.git] / data / lalr1.cc
CommitLineData
a75c057f 1m4_divert(-1)
60491a94 2# C++ skeleton for Bison
b61c6978 3# Copyright (C) 2002, 2003 Free Software Foundation, Inc.
60491a94
AD
4
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18# 02111-1307 USA
19
66d30cd4
AD
20## ---------------- ##
21## Default values. ##
22## ---------------- ##
23
66d30cd4
AD
24# Default Parser class name.
25m4_define_default([b4_parser_class_name], [Parser])
26
27
28
29## ----------------- ##
30## Semantic Values. ##
31## ----------------- ##
32
33
82b6cb3f
AD
34# b4_lhs_value([TYPE])
35# --------------------
36# Expansion of $<TYPE>$.
37m4_define([b4_lhs_value],
38[yyval[]m4_ifval([$1], [.$1])])
39
40
41# b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
42# --------------------------------------
43# Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
44# symbols on RHS.
45m4_define([b4_rhs_value],
6ad762a8 46[semantic_stack_@{m4_eval([$1 - $2])@}m4_ifval([$3], [.$3])])
82b6cb3f 47
66d30cd4 48m4_define_default([b4_location_type], [Location])
82b6cb3f
AD
49
50# b4_lhs_location()
51# -----------------
52# Expansion of @$.
53m4_define([b4_lhs_location],
54[yyloc])
55
56
57# b4_rhs_location(RULE-LENGTH, NUM)
58# ---------------------------------
59# Expansion of @NUM, where the current rule has RULE-LENGTH symbols
60# on RHS.
61m4_define([b4_rhs_location],
6ad762a8 62[location_stack_@{m4_eval([$1 - $2])@}])
82b6cb3f
AD
63
64
af27eacb 65m4_define([b4_inherit],
0d8bed56 66 [m4_ifdef([b4_root],
af27eacb
RA
67 [: public b4_root
68],
69 [])])
70
71m4_define([b4_param],
72 [m4_ifdef([b4_root],
73 [,
74 const Param& param],
75 [])])
76
77m4_define([b4_constructor],
78 [m4_ifdef([b4_root],
79 [b4_root (param),
80 ],
81 [])])
82
98254360 83
caf37a36
ADL
84# b4_parse_param_decl
85# -------------------
86# Constructor's extra arguments.
87m4_define([b4_parse_param_decl],
88 [m4_ifset([b4_parse_param], [, b4_c_ansi_formals(b4_parse_param)])])
89
90# b4_parse_param_cons
91# -------------------
92# constructor's extra initialisations.
93m4_define([b4_parse_param_cons],
94 [m4_ifset([b4_parse_param],
95 [,
96 b4_cc_constructor_calls(b4_parse_param)])])
97m4_define([b4_cc_constructor_calls],
98 [m4_map_sep([b4_cc_constructor_call], [,
99 ], [$@])])
100m4_define([b4_cc_constructor_call],
101 [$2($2)])
102
103# b4_parse_param_vars
104# -------------------
105# Extra instance variables.
106m4_define([b4_parse_param_vars],
107 [m4_ifset([b4_parse_param],
108 [
109 /* User arguments. */
110b4_cc_var_decls(b4_parse_param)])])
111m4_define([b4_cc_var_decls],
112 [m4_map_sep([b4_cc_var_decl], [
113], [$@])])
114m4_define([b4_cc_var_decl],
115 [ $1;])
116
b526ee61
AD
117# We do want M4 expansion after # for CPP macros.
118m4_changecom()
98254360 119m4_divert(0)dnl
b61c6978
PE
120m4_if(b4_defines_flag, 0, [],
121[@output @output_header_name@
fb8135fa 122b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison],
b61c6978 123 [2002, 2003])[
c5e3e510
AD
124/* FIXME: This is wrong, we want computed header guards.
125 I don't know why the macros are missing now. :( */
126#ifndef PARSER_HEADER_H
127# define PARSER_HEADER_H
2b548aa6
RA
128
129#include "stack.hh"
2b548aa6
RA
130#include "location.hh"
131
8d69a1a3 132#include <string>
717be197 133#include <iostream>
50997c6e 134
4162fa07 135/* Using locations. */
c5e3e510 136#define YYLSP_NEEDED ]b4_locations_flag[
4162fa07 137
c5e3e510 138]b4_token_defines(b4_tokens)[
17acead5 139
0dd1580a 140/* Copy the first part of user declarations. */
c5e3e510 141]b4_pre_prologue[
4162fa07 142
996b1c7e 143]/* Line __line__ of lalr1.cc. */
c5e3e510 144b4_syncline([@oline@], [@ofile@])[
e96c9728 145
69e2658b
RA
146/* Enabling traces. */
147#ifndef YYDEBUG
c5e3e510 148# define YYDEBUG ]b4_debug[
69e2658b
RA
149#endif
150
151/* Enabling verbose error message. */
152#ifndef YYERROR_VERBOSE
c5e3e510 153# define YYERROR_VERBOSE ]b4_error_verbose[
69e2658b
RA
154#endif
155
98254360 156#ifndef YYSTYPE
c5e3e510 157]m4_ifdef([b4_stype],
437c2d80 158[b4_syncline([b4_stype_line], [b4_filename])
e96c9728 159typedef union b4_stype yystype;
996b1c7e 160/* Line __line__ of lalr1.cc. */
6ad762a8 161b4_syncline([@oline@], [@ofile@])],
c5e3e510 162[typedef int yystype;])[
98254360
RA
163# define YYSTYPE yystype
164#endif
165
0dd1580a 166/* Copy the second part of user declarations. */
c5e3e510 167]b4_post_prologue[
0dd1580a 168
996b1c7e 169]/* Line __line__ of lalr1.cc. */
c5e3e510 170b4_syncline([@oline@], [@ofile@])[
374f5a14
RA
171#ifndef YYLLOC_DEFAULT
172# define YYLLOC_DEFAULT(Current, Rhs, N) \
0ae99356 173 ((Current).end = Rhs[N].end)
374f5a14
RA
174#endif
175
2b548aa6
RA
176namespace yy
177{
c5e3e510 178 class ]b4_parser_class_name[;
3f3eed27 179
2b548aa6
RA
180 template < typename P >
181 struct Traits
182 {
183 };
184
185 template < >
c5e3e510 186 struct Traits< ]b4_parser_class_name[ >
2b548aa6 187 {
c5e3e510
AD
188 typedef ]b4_int_type_for([b4_translate])[ TokenNumberType;
189 typedef ]b4_int_type_for([b4_rhs])[ RhsNumberType;
50997c6e
RA
190 typedef int StateType;
191 typedef yystype SemanticType;
c5e3e510 192 typedef ]b4_location_type[ LocationType;
2b548aa6
RA
193 };
194}
195
2b548aa6
RA
196namespace yy
197{
c5e3e510 198 class ]b4_parser_class_name b4_inherit[
2b548aa6
RA
199 {
200 public:
3f3eed27 201
c5e3e510
AD
202 typedef Traits< ]b4_parser_class_name[ >::TokenNumberType TokenNumberType;
203 typedef Traits< ]b4_parser_class_name[ >::RhsNumberType RhsNumberType;
204 typedef Traits< ]b4_parser_class_name[ >::StateType StateType;
205 typedef Traits< ]b4_parser_class_name[ >::SemanticType SemanticType;
206 typedef Traits< ]b4_parser_class_name[ >::LocationType LocationType;
2b548aa6
RA
207
208 typedef Stack< StateType > StateStack;
209 typedef Stack< SemanticType > SemanticStack;
210 typedef Stack< LocationType > LocationStack;
211
8d69a1a3 212#if YYLSP_NEEDED
c5e3e510 213 ]b4_parser_class_name[ (bool debug,
caf37a36 214 LocationType initlocation][]b4_param[]b4_parse_param_decl[) :
c5e3e510 215 ]b4_constructor[][debug_ (debug),
717be197 216 cdebug_ (std::cerr),
caf37a36 217 initlocation_ (initlocation)]b4_parse_param_cons[
8d69a1a3 218#else
caf37a36 219 ]b4_parser_class_name[ (bool debug][]b4_param[]b4_parse_param_decl[) :
c5e3e510 220 ]b4_constructor[][debug_ (debug),
caf37a36 221 cdebug_ (std::cerr)]b4_parse_param_cons[
8d69a1a3 222#endif
50997c6e 223 {
50997c6e
RA
224 }
225
c5e3e510 226 virtual ~]b4_parser_class_name[ ()
2b548aa6 227 {
2b548aa6
RA
228 }
229
230 virtual int parse ();
231
232 private:
3f3eed27 233
69e2658b 234 virtual void lex_ ();
4bb2bc3f 235 virtual void error_ ();
4aacc3a7 236 virtual void print_ ();
4bb2bc3f 237
2b548aa6 238 /* Stacks. */
69e2658b
RA
239 StateStack state_stack_;
240 SemanticStack semantic_stack_;
241 LocationStack location_stack_;
2b548aa6
RA
242
243 /* Tables. */
c5e3e510 244 static const ]b4_int_type_for([b4_pact])[ pact_[];
0c3c1f98 245 static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ pact_ninf_;
c5e3e510
AD
246 static const ]b4_int_type_for([b4_defact])[ defact_[];
247 static const ]b4_int_type_for([b4_pgoto])[ pgoto_[];
248 static const ]b4_int_type_for([b4_defgoto])[ defgoto_[];
249 static const ]b4_int_type_for([b4_table])[ table_[];
0c3c1f98 250 static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ table_ninf_;
c5e3e510
AD
251 static const ]b4_int_type_for([b4_check])[ check_[];
252 static const ]b4_int_type_for([b4_r1])[ r1_[];
253 static const ]b4_int_type_for([b4_r2])[ r2_[];
69e2658b
RA
254
255#if YYDEBUG || YYERROR_VERBOSE
c5e3e510 256 static const char* const name_[];
69e2658b 257#endif
2b548aa6
RA
258
259 /* More tables, for debugging. */
69e2658b 260#if YYDEBUG
c5e3e510
AD
261 static const RhsNumberType rhs_[];
262 static const ]b4_int_type_for([b4_prhs])[ prhs_[];
263 static const ]b4_int_type_for([b4_rline])[ rline_[];
264 static const ]b4_int_type_for([b4_stos])[ stos_[];
265 static const ]b4_int_type_for([b4_toknum])[ token_number_[];
5348bfbe 266 virtual void reduce_print_ (int yyrule);
25f66e1a 267 virtual void stack_print_ ();
69e2658b 268#endif
2b548aa6
RA
269
270 /* Even more tables. */
680e8701 271 static inline TokenNumberType translate_ (int token);
2b548aa6 272
762a801e 273 /* Constants. */
50997c6e 274 static const int eof_;
39912f52 275 /* LAST_ -- Last index in TABLE_. */
69e2658b 276 static const int last_;
69e2658b 277 static const int nnts_;
50997c6e 278 static const int empty_;
69e2658b 279 static const int final_;
762a801e
RA
280 static const int terror_;
281 static const int errcode_;
50997c6e 282 static const int ntokens_;
007a50a4
AD
283 static const unsigned user_token_number_max_;
284 static const TokenNumberType undef_token_;
2b548aa6
RA
285
286 /* State. */
69e2658b
RA
287 int n_;
288 int len_;
69e2658b 289 int state_;
4bb2bc3f 290
717be197
AD
291 /* Debugging. */
292 int debug_;
293 std::ostream &cdebug_;
294
69e2658b
RA
295 /* Lookahead and lookahead in internal form. */
296 int looka_;
297 int ilooka_;
4bb2bc3f
RA
298
299 /* Message. */
300 std::string message;
301
374f5a14 302 /* Semantic value and location of lookahead token. */
2b548aa6
RA
303 SemanticType value;
304 LocationType location;
8d69a1a3 305
6ad762a8 306 /* @@$ and $$. */
374f5a14
RA
307 SemanticType yyval;
308 LocationType yyloc;
309
8d69a1a3
RA
310 /* Initial location. */
311 LocationType initlocation_;
caf37a36 312]b4_parse_param_vars[
2b548aa6
RA
313 };
314}
315
c5e3e510 316#endif /* ! defined PARSER_HEADER_H */]
b61c6978 317])dnl
6ad762a8 318@output @output_parser_name@
fb8135fa 319b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison],
b61c6978 320 [2002, 2003])
98254360 321
b61c6978 322m4_if(b4_defines_flag, 0, [], [#include @output_header_name@])[
50997c6e 323
2b548aa6 324/* Enable debugging if requested. */
50997c6e 325#if YYDEBUG
717be197 326# define YYCDEBUG if (debug_) cdebug_
5348bfbe
AD
327# define YY_REDUCE_PRINT(Rule) \
328do { \
329 if (debug_) \
330 reduce_print_ (Rule); \
331} while (0)
25f66e1a
AD
332# define YY_STACK_PRINT() \
333do { \
334 if (debug_) \
335 stack_print_ (); \
336} while (0)
2b548aa6 337#else /* !YYDEBUG */
717be197 338# define YYCDEBUG if (0) cdebug_
5348bfbe 339# define YY_REDUCE_PRINT(Rule)
25f66e1a 340# define YY_STACK_PRINT()
2b548aa6
RA
341#endif /* !YYDEBUG */
342
60a777aa
AD
343#define YYACCEPT goto yyacceptlab
344#define YYABORT goto yyabortlab
47301314 345#define YYERROR goto yyerrorlab
60a777aa
AD
346
347
2b548aa6 348int
c5e3e510 349yy::]b4_parser_class_name[::parse ()
2b548aa6 350{
4bb2bc3f
RA
351 int nerrs = 0;
352 int errstatus = 0;
353
3ae831b4
AD
354 /* Initialize the stacks. The initial state will be pushed in
355 yynewstate, since the latter expects the semantical and the
356 location values to have been already stored, initialize these
357 stacks with a primary value. */
69e2658b
RA
358 state_stack_ = StateStack (0);
359 semantic_stack_ = SemanticStack (1);
360 location_stack_ = LocationStack (1);
2b548aa6 361
2b548aa6 362 /* Start. */
69e2658b
RA
363 state_ = 0;
364 looka_ = empty_;
8d69a1a3
RA
365#if YYLSP_NEEDED
366 location = initlocation_;
367#endif
717be197 368 YYCDEBUG << "Starting parse" << std::endl;
2b548aa6
RA
369
370 /* New state. */
371 yynewstate:
69e2658b 372 state_stack_.push (state_);
717be197 373 YYCDEBUG << "Entering state " << state_ << std::endl;
50997c6e 374 goto yybackup;
2b548aa6
RA
375
376 /* Backup. */
377 yybackup:
378
379 /* Try to take a decision without lookahead. */
c5e3e510 380 n_ = pact_[state_];
12b0043a 381 if (n_ == pact_ninf_)
2b548aa6
RA
382 goto yydefault;
383
384 /* Read a lookahead token. */
69e2658b 385 if (looka_ == empty_)
2b548aa6 386 {
717be197 387 YYCDEBUG << "Reading a token: ";
69e2658b 388 lex_ ();
2b548aa6
RA
389 }
390
391 /* Convert token to internal form. */
69e2658b 392 if (looka_ <= 0)
2b548aa6 393 {
69e2658b
RA
394 looka_ = eof_;
395 ilooka_ = 0;
717be197 396 YYCDEBUG << "Now at end of input." << std::endl;
2b548aa6
RA
397 }
398 else
399 {
69e2658b 400 ilooka_ = translate_ (looka_);
50997c6e
RA
401#if YYDEBUG
402 if (debug_)
403 {
717be197 404 YYCDEBUG << "Next token is " << looka_
c5e3e510 405 << " (" << name_[ilooka_];
4aacc3a7 406 print_ ();
717be197 407 YYCDEBUG << ')' << std::endl;
50997c6e 408 }
2b548aa6
RA
409#endif
410 }
411
47301314
AD
412 /* If the proper action on seeing token YYTOKEN is to reduce or to
413 detect an error, take that action. */
69e2658b 414 n_ += ilooka_;
c5e3e510 415 if (n_ < 0 || last_ < n_ || check_[n_] != ilooka_)
2b548aa6
RA
416 goto yydefault;
417
418 /* Reduce or error. */
c5e3e510 419 n_ = table_[n_];
69e2658b 420 if (n_ < 0)
2b548aa6 421 {
12b0043a 422 if (n_ == table_ninf_)
2b548aa6
RA
423 goto yyerrlab;
424 else
425 {
69e2658b 426 n_ = -n_;
2b548aa6
RA
427 goto yyreduce;
428 }
429 }
69e2658b 430 else if (n_ == 0)
2b548aa6 431 goto yyerrlab;
a75c057f 432
2b548aa6 433 /* Accept? */
69e2658b 434 if (n_ == final_)
2b548aa6
RA
435 goto yyacceptlab;
436
437 /* Shift the lookahead token. */
fc049e9c 438#if YYDEBUG
717be197 439 YYCDEBUG << "Shifting token " << looka_
fc049e9c
AD
440 << " (" << name_[ilooka_] << "), ";
441#endif
2b548aa6
RA
442
443 /* Discard the token being shifted unless it is eof. */
69e2658b
RA
444 if (looka_ != eof_)
445 looka_ = empty_;
2b548aa6 446
69e2658b
RA
447 semantic_stack_.push (value);
448 location_stack_.push (location);
8d69a1a3
RA
449
450 /* Count tokens shifted since error; after three, turn off error
451 status. */
452 if (errstatus)
453 --errstatus;
454
69e2658b 455 state_ = n_;
2b548aa6
RA
456 goto yynewstate;
457
47301314
AD
458/*-----------------------------------------------------------.
459| yydefault -- do the default action for the current state. |
460`-----------------------------------------------------------*/
2b548aa6 461 yydefault:
c5e3e510 462 n_ = defact_[state_];
69e2658b 463 if (n_ == 0)
2b548aa6 464 goto yyerrlab;
50997c6e 465 goto yyreduce;
2b548aa6 466
47301314
AD
467/*-----------------------------.
468| yyreduce -- Do a reduction. |
469`-----------------------------*/
2b548aa6 470 yyreduce:
c5e3e510 471 len_ = r2_[n_];
47301314
AD
472 /* If LEN_ is nonzero, implement the default value of the action:
473 `$$ = $1'. Otherwise, use the top of the stack.
474
475 Otherwise, the following line sets YYVAL to garbage.
476 This behavior is undocumented and Bison
477 users should not rely upon it. */
69e2658b 478 if (len_)
50997c6e 479 {
c5e3e510
AD
480 yyval = semantic_stack_[len_ - 1];
481 yyloc = location_stack_[len_ - 1];
50997c6e
RA
482 }
483 else
69e2658b 484 {
c5e3e510
AD
485 yyval = semantic_stack_[0];
486 yyloc = location_stack_[0];
50997c6e 487 }
2b548aa6 488
374f5a14
RA
489 if (len_)
490 {
491 Slice< LocationType, LocationStack > slice (location_stack_, len_);
492 YYLLOC_DEFAULT (yyloc, slice, len_);
493 }
5348bfbe 494 YY_REDUCE_PRINT (n_);
45119f04
RA
495 switch (n_)
496 {
c5e3e510 497 ]b4_actions[
45119f04 498 }
a75c057f 499
996b1c7e 500]/* Line __line__ of lalr1.cc. */
c5e3e510 501b4_syncline([@oline@], [@ofile@])[
06446ccf 502
69e2658b
RA
503 state_stack_.pop (len_);
504 semantic_stack_.pop (len_);
505 location_stack_.pop (len_);
2b548aa6 506
25f66e1a 507 YY_STACK_PRINT ();
a75c057f 508
374f5a14
RA
509 semantic_stack_.push (yyval);
510 location_stack_.push (yyloc);
2b548aa6
RA
511
512 /* Shift the result of the reduction. */
c5e3e510
AD
513 n_ = r1_[n_];
514 state_ = pgoto_[n_ - ntokens_] + state_stack_[0];
515 if (0 <= state_ && state_ <= last_ && check_[state_] == state_stack_[0])
516 state_ = table_[state_];
2b548aa6 517 else
c5e3e510 518 state_ = defgoto_[n_ - ntokens_];
2b548aa6
RA
519 goto yynewstate;
520
47301314
AD
521/*------------------------------------.
522| yyerrlab -- here on detecting error |
523`------------------------------------*/
2b548aa6 524 yyerrlab:
4bb2bc3f
RA
525 /* If not already recovering from an error, report this error. */
526 if (!errstatus)
527 {
528 ++nerrs;
a75c057f 529
69e2658b 530#if YYERROR_VERBOSE
c5e3e510 531 n_ = pact_[state_];
12b0043a 532 if (pact_ninf_ < n_ && n_ < last_)
4bb2bc3f 533 {
6e649e65 534 message = "syntax error, unexpected ";
c5e3e510 535 message += name_[ilooka_];
4bb2bc3f
RA
536 {
537 int count = 0;
c4749565
AD
538 /* Start YYX at -YYN if negative to avoid negative indexes in
539 YYCHECK. */
540 int xbegin = n_ < 0 ? -n_ : 0;
541 /* Stay within bounds of both yycheck and yytname. */
542 int checklim = last_ - n_;
543 int xend = checklim < ntokens_ ? checklim : ntokens_;
544 for (int x = xbegin; x < xend; ++x)
c5e3e510 545 if (check_[x + n_] == x && x != terror_)
4bb2bc3f
RA
546 ++count;
547 if (count < 5)
548 {
549 count = 0;
1d4055aa
PE
550 for (int x1 = xbegin; x1 < xend; ++x1)
551 if (check_[x1 + n_] == x1 && x1 != terror_)
4bb2bc3f 552 {
a75c057f 553 message += (!count++) ? ", expecting " : " or ";
1d4055aa 554 message += name_[x1];
4bb2bc3f
RA
555 }
556 }
557 }
558 }
559 else
69e2658b 560#endif
6e649e65 561 message = "syntax error";
8d69a1a3 562 error_ ();
4bb2bc3f 563 }
60a777aa 564
762a801e
RA
565 if (errstatus == 3)
566 {
567 /* If just tried and failed to reuse lookahead token after an
568 error, discard it. */
569
570 /* Return failure if at end of input. */
47301314
AD
571 if (looka_ <= eof_)
572 {
573 /* If at end of input, pop the error token,
574 then the rest of the stack, then return failure. */
575 if (looka_ == eof_)
576 for (;;)
577 {
578 state_stack_.pop ();
579 semantic_stack_.pop ();
580 location_stack_.pop ();
581 if (state_stack_.height () == 1)
582 YYABORT;
583// YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
584// FIXME: yydestruct (yystos[*yyssp], yyvsp]b4_location_if([, yylsp])[);
585 }
586 }
587 else
588 {
7548fed2 589#if YYDEBUG
47301314
AD
590 YYCDEBUG << "Discarding token " << looka_
591 << " (" << name_[ilooka_] << ")." << std::endl;
592// yydestruct (yytoken, &yylval]b4_location_if([, &yylloc])[);
7548fed2 593#endif
47301314
AD
594 looka_ = empty_;
595 }
762a801e
RA
596 }
597
598 /* Else will try to reuse lookahead token after shifting the error
599 token. */
47301314
AD
600 goto yyerrlab1;
601
602
603/*---------------------------------------------------.
604| yyerrorlab -- error raised explicitly by YYERROR. |
605`---------------------------------------------------*/
606yyerrorlab:
607
608 state_stack_.pop (len_);
609 semantic_stack_.pop (len_);
610 location_stack_.pop (len_);
611 state_ = state_stack_[0];
612 goto yyerrlab1;
762a801e 613
47301314
AD
614/*-------------------------------------------------------------.
615| yyerrlab1 -- common code for both syntax error and YYERROR. |
616`-------------------------------------------------------------*/
617yyerrlab1:
618 errstatus = 3; /* Each real token shifted decrements this. */
762a801e 619
769b430f
AD
620 for (;;)
621 {
c5e3e510 622 n_ = pact_[state_];
12b0043a 623 if (n_ != pact_ninf_)
769b430f
AD
624 {
625 n_ += terror_;
c5e3e510 626 if (0 <= n_ && n_ <= last_ && check_[n_] == terror_)
769b430f 627 {
c5e3e510 628 n_ = table_[n_];
769b430f
AD
629 if (0 < n_)
630 break;
631 }
632 }
633
634 /* Pop the current state because it cannot handle the error token. */
3ae831b4 635 if (state_stack_.height () == 1)
47301314 636 YYABORT;
762a801e
RA
637
638#if YYDEBUG
769b430f
AD
639 if (debug_)
640 {
c5e3e510 641 if (stos_[state_] < ntokens_)
769b430f 642 {
717be197 643 YYCDEBUG << "Error: popping token "
c5e3e510
AD
644 << token_number_[stos_[state_]]
645 << " (" << name_[stos_[state_]];
769b430f 646# ifdef YYPRINT
c5e3e510 647 YYPRINT (stderr, token_number_[stos_[state_]],
769b430f
AD
648 semantic_stack_.top ());
649# endif
717be197 650 YYCDEBUG << ')' << std::endl;
769b430f
AD
651 }
652 else
653 {
717be197 654 YYCDEBUG << "Error: popping nonterminal ("
c5e3e510 655 << name_[stos_[state_]] << ')' << std::endl;
769b430f
AD
656 }
657 }
762a801e
RA
658#endif
659
47301314 660 state_stack_.pop ();
769b430f 661 semantic_stack_.pop ();
47301314
AD
662 location_stack_.pop ();
663 state_ = state_stack_[0];
25f66e1a 664 YY_STACK_PRINT ();
762a801e 665 }
762a801e 666
69e2658b 667 if (n_ == final_)
762a801e
RA
668 goto yyacceptlab;
669
717be197 670 YYCDEBUG << "Shifting error token, ";
762a801e 671
69e2658b
RA
672 semantic_stack_.push (value);
673 location_stack_.push (location);
762a801e 674
69e2658b 675 state_ = n_;
762a801e
RA
676 goto yynewstate;
677
2b548aa6
RA
678 /* Accept. */
679 yyacceptlab:
680 return 0;
762a801e
RA
681
682 /* Abort. */
683 yyabortlab:
684 return 1;
2b548aa6
RA
685}
686
69e2658b 687void
c5e3e510 688yy::]b4_parser_class_name[::lex_ ()
69e2658b
RA
689{
690#if YYLSP_NEEDED
691 looka_ = yylex (&value, &location);
692#else
693 looka_ = yylex (&value);
694#endif
695}
696
5348bfbe 697
c5e3e510 698/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
2b548aa6 699 STATE-NUM. */
0c3c1f98 700const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) yy::b4_parser_class_name::pact_ninf_ = b4_pact_ninf[;
c5e3e510
AD
701const ]b4_int_type_for([b4_pact])[
702yy::]b4_parser_class_name[::pact_[] =
2b548aa6 703{
c5e3e510 704 ]b4_pact[
2b548aa6
RA
705};
706
c5e3e510 707/* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
2b548aa6
RA
708 doesn't specify something else to do. Zero means the default is an
709 error. */
c5e3e510
AD
710const ]b4_int_type_for([b4_defact])[
711yy::]b4_parser_class_name[::defact_[] =
2b548aa6 712{
c5e3e510 713 ]b4_defact[
2b548aa6
RA
714};
715
c5e3e510
AD
716/* YYPGOTO[NTERM-NUM]. */
717const ]b4_int_type_for([b4_pgoto])[
718yy::]b4_parser_class_name[::pgoto_[] =
2b548aa6 719{
c5e3e510 720 ]b4_pgoto[
2b548aa6
RA
721};
722
c5e3e510
AD
723/* YYDEFGOTO[NTERM-NUM]. */
724const ]b4_int_type_for([b4_defgoto])[
725yy::]b4_parser_class_name[::defgoto_[] =
2b548aa6 726{
c5e3e510 727 ]b4_defgoto[
2b548aa6
RA
728};
729
c5e3e510 730/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
2b548aa6
RA
731 positive, shift that token. If negative, reduce the rule which
732 number is the opposite. If zero, do what YYDEFACT says. */
0c3c1f98 733const ]b4_int_type(b4_table_ninf, b4_table_ninf) yy::b4_parser_class_name::table_ninf_ = b4_table_ninf[;
c5e3e510
AD
734const ]b4_int_type_for([b4_table])[
735yy::]b4_parser_class_name[::table_[] =
2b548aa6 736{
c5e3e510 737 ]b4_table[
2b548aa6
RA
738};
739
740/* YYCHECK. */
c5e3e510
AD
741const ]b4_int_type_for([b4_check])[
742yy::]b4_parser_class_name[::check_[] =
2b548aa6 743{
c5e3e510 744 ]b4_check[
2b548aa6
RA
745};
746
769b430f 747#if YYDEBUG
c5e3e510 748/* STOS_[STATE-NUM] -- The (internal number of the) accessing
769b430f 749 symbol of state STATE-NUM. */
c5e3e510
AD
750const ]b4_int_type_for([b4_stos])[
751yy::]b4_parser_class_name[::stos_[] =
769b430f 752{
c5e3e510 753 ]b4_stos[
769b430f
AD
754};
755
c5e3e510 756/* TOKEN_NUMBER_[YYLEX-NUM] -- Internal token number corresponding
769b430f 757 to YYLEX-NUM. */
c5e3e510
AD
758const ]b4_int_type_for([b4_toknum])[
759yy::]b4_parser_class_name[::token_number_[] =
769b430f 760{
c5e3e510 761 ]b4_toknum[
769b430f
AD
762};
763#endif
764
c5e3e510
AD
765/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
766const ]b4_int_type_for([b4_r1])[
767yy::]b4_parser_class_name[::r1_[] =
2b548aa6 768{
c5e3e510 769 ]b4_r1[
2b548aa6
RA
770};
771
c5e3e510
AD
772/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
773const ]b4_int_type_for([b4_r2])[
774yy::]b4_parser_class_name[::r2_[] =
2b548aa6 775{
c5e3e510 776 ]b4_r2[
2b548aa6
RA
777};
778
69e2658b 779#if YYDEBUG || YYERROR_VERBOSE
c5e3e510 780/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
2b548aa6
RA
781 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
782const char*
c5e3e510 783const yy::]b4_parser_class_name[::name_[] =
2b548aa6 784{
c5e3e510 785 ]b4_tname[
2b548aa6 786};
69e2658b 787#endif
2b548aa6 788
69e2658b 789#if YYDEBUG
2b548aa6 790/* YYRHS -- A `-1'-separated list of the rules' RHS. */
c5e3e510
AD
791const yy::]b4_parser_class_name[::RhsNumberType
792yy::]b4_parser_class_name[::rhs_[] =
2b548aa6 793{
c5e3e510 794 ]b4_rhs[
2b548aa6
RA
795};
796
c5e3e510 797/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
2b548aa6 798 YYRHS. */
c5e3e510
AD
799const ]b4_int_type_for([b4_prhs])[
800yy::]b4_parser_class_name[::prhs_[] =
2b548aa6 801{
c5e3e510 802 ]b4_prhs[
2b548aa6
RA
803};
804
c5e3e510
AD
805/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
806const ]b4_int_type_for([b4_rline])[
807yy::]b4_parser_class_name[::rline_[] =
69e2658b 808{
c5e3e510 809 ]b4_rline[
69e2658b 810};
5348bfbe 811
25f66e1a
AD
812/** Print the state stack from its BOTTOM up to its TOP (included). */
813
814void
815yy::]b4_parser_class_name[::stack_print_ ()
816{
817 cdebug_ << "state stack now";
818 for (StateStack::ConstIterator i = state_stack_.begin ();
819 i != state_stack_.end (); ++i)
820 cdebug_ << ' ' << *i;
821 cdebug_ << std::endl;
822}
823
5348bfbe
AD
824/** Report that the YYRULE is going to be reduced. */
825
826void
827yy::]b4_parser_class_name[::reduce_print_ (int yyrule)
828{
5348bfbe
AD
829 unsigned int yylno = rline_[yyrule];
830 /* Print the symbols being reduced, and their result. */
831 cdebug_ << "Reducing via rule " << n_ - 1 << " (line " << yylno << "), ";
832 for (]b4_int_type_for([b4_prhs])[ i = prhs_[n_];
833 0 <= rhs_[i]; ++i)
834 cdebug_ << name_[rhs_[i]] << ' ';
835 cdebug_ << "-> " << name_[r1_[n_]] << std::endl;
836}
837#endif // YYDEBUG
69e2658b 838
2b548aa6 839/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
c5e3e510
AD
840yy::]b4_parser_class_name[::TokenNumberType
841yy::]b4_parser_class_name[::translate_ (int token)
2b548aa6 842{
a75c057f 843 static
680e8701 844 const TokenNumberType
1d4055aa 845 translate_table[] =
2b548aa6 846 {
c5e3e510 847 ]b4_translate[
2b548aa6 848 };
007a50a4 849 if ((unsigned) token <= user_token_number_max_)
1d4055aa 850 return translate_table[token];
007a50a4
AD
851 else
852 return undef_token_;
2b548aa6
RA
853}
854
c5e3e510
AD
855const int yy::]b4_parser_class_name[::eof_ = 0;
856const int yy::]b4_parser_class_name[::last_ = ]b4_last[;
857const int yy::]b4_parser_class_name[::nnts_ = ]b4_nterms_number[;
858const int yy::]b4_parser_class_name[::empty_ = -2;
859const int yy::]b4_parser_class_name[::final_ = ]b4_final_state_number[;
860const int yy::]b4_parser_class_name[::terror_ = 1;
861const int yy::]b4_parser_class_name[::errcode_ = 256;
862const int yy::]b4_parser_class_name[::ntokens_ = ]b4_tokens_number[;
66d30cd4 863
c5e3e510
AD
864const unsigned yy::]b4_parser_class_name[::user_token_number_max_ = ]b4_user_token_number_max[;
865const yy::]b4_parser_class_name[::TokenNumberType yy::]b4_parser_class_name[::undef_token_ = ]b4_undef_token_number[;
2b548aa6 866
c5e3e510 867]b4_epilogue
21846f69 868dnl
6ad762a8 869@output stack.hh
7548fed2 870b4_copyright([Stack handling for Bison C++ parsers], [2002, 2003])[
98254360 871
2b548aa6
RA
872#ifndef BISON_STACK_HH
873# define BISON_STACK_HH
874
45119f04 875#include <deque>
2b548aa6
RA
876
877namespace yy
878{
45119f04 879 template < class T, class S = std::deque< T > >
2b548aa6
RA
880 class Stack
881 {
882 public:
883
884 typedef typename S::iterator Iterator;
885 typedef typename S::const_iterator ConstIterator;
886
887 Stack () : seq_ ()
888 {
889 }
890
891 Stack (unsigned n) : seq_ (n)
892 {
893 }
894
895 inline
896 T&
1d4055aa 897 operator [] (unsigned i)
2b548aa6 898 {
1d4055aa 899 return seq_[i];
2b548aa6
RA
900 }
901
902 inline
903 const T&
1d4055aa 904 operator [] (unsigned i) const
2b548aa6 905 {
1d4055aa 906 return seq_[i];
2b548aa6
RA
907 }
908
909 inline
910 void
911 push (const T& t)
912 {
45119f04 913 seq_.push_front (t);
2b548aa6
RA
914 }
915
916 inline
917 void
918 pop (unsigned n = 1)
919 {
920 for (; n; --n)
45119f04 921 seq_.pop_front ();
2b548aa6
RA
922 }
923
762a801e
RA
924 inline
925 unsigned
926 height () const
927 {
928 return seq_.size ();
929 }
930
2b548aa6
RA
931 inline ConstIterator begin () const { return seq_.begin (); }
932 inline ConstIterator end () const { return seq_.end (); }
933
934 private:
935
936 S seq_;
937 };
374f5a14
RA
938
939 template < class T, class S = Stack< T > >
940 class Slice
941 {
942 public:
943
944 Slice (const S& stack,
945 unsigned range) : stack_ (stack),
946 range_ (range)
947 {
948 }
949
950 inline
951 const T&
1d4055aa 952 operator [] (unsigned i) const
374f5a14 953 {
1d4055aa 954 return stack_[range_ - i];
374f5a14
RA
955 }
956
957 private:
958
959 const S& stack_;
960 unsigned range_;
961 };
2b548aa6
RA
962}
963
c5e3e510 964#endif // not BISON_STACK_HH]
21846f69 965dnl
5d003116
AD
966@output position.hh
967b4_copyright([Position class for Bison C++ parsers], [2002, 2003])[
98254360 968
5d003116
AD
969/**
970 ** \file position.hh
971 ** Define the Location class.
972 */
973
974#ifndef BISON_POSITION_HH
975# define BISON_POSITION_HH
2b548aa6 976
7548fed2
AD
977# include <iostream>
978# include <string>
979
2b548aa6
RA
980namespace yy
981{
5d003116 982 /** \brief Abstract a Position. */
7548fed2 983 class Position
2b548aa6 984 {
7548fed2 985 public:
5d003116
AD
986 /** \brief Initial column number. */
987 static const unsigned int initial_column = 0;
988 /** \brief Initial line number. */
989 static const unsigned int initial_line = 1;
990
991 /** \name Ctor & dtor.
992 ** \{ */
993 public:
994 /** \brief Construct a Position. */
995 Position () :
996 filename (),
997 line (initial_line),
998 column (initial_column)
999 {
1000 }
1001 /** \} */
1002
7548fed2 1003
5d003116
AD
1004 /** \name Line and Column related manipulators
1005 ** \{ */
1006 public:
2ffbee0e
PE
1007 /** \brief (line related) Advance to the COUNT next lines. */
1008 inline void lines (int count = 1)
5d003116
AD
1009 {
1010 column = initial_column;
2ffbee0e 1011 line += count;
5d003116
AD
1012 }
1013
2ffbee0e
PE
1014 /** \brief (column related) Advance to the COUNT next columns. */
1015 inline void columns (int count = 1)
5d003116 1016 {
f939fc12
AD
1017 int leftmost = initial_column;
1018 int current = column;
2ffbee0e
PE
1019 if (leftmost <= current + count)
1020 column += count;
2cdc240e
AD
1021 else
1022 column = initial_column;
5d003116
AD
1023 }
1024 /** \} */
1025
1026 public:
1027 /** \brief File name to which this position refers. */
7548fed2 1028 std::string filename;
5d003116
AD
1029 /** \brief Current line number. */
1030 unsigned int line;
1031 /** \brief Current column number. */
1032 unsigned int column;
2b548aa6
RA
1033 };
1034
5d003116
AD
1035 /** \brief Add and assign a Position. */
1036 inline const Position&
1037 operator+= (Position& res, const int width)
1038 {
1039 res.columns (width);
1040 return res;
1041 }
1042
1043 /** \brief Add two Position objects. */
1044 inline const Position
1045 operator+ (const Position& begin, const int width)
1046 {
1047 Position res = begin;
1048 return res += width;
1049 }
1050
1051 /** \brief Add and assign a Position. */
1052 inline const Position&
1053 operator-= (Position& res, const int width)
1054 {
1055 return res += -width;
1056 }
1057
1058 /** \brief Add two Position objects. */
1059 inline const Position
1060 operator- (const Position& begin, const int width)
1061 {
1062 return begin + -width;
1063 }
1064
1065 /** \brief Intercept output stream redirection.
1066 ** \param ostr the destination output stream
1067 ** \param pos a reference to the Position to redirect
1068 */
7548fed2
AD
1069 inline std::ostream&
1070 operator<< (std::ostream& ostr, const Position& pos)
1071 {
b81a6e01 1072 if (!pos.filename.empty ())
7548fed2 1073 ostr << pos.filename << ':';
5d003116 1074 return ostr << pos.line << '.' << pos.column;
7548fed2
AD
1075 }
1076
5d003116
AD
1077}
1078#endif // not BISON_POSITION_HH]
1079@output location.hh
1080b4_copyright([Location class for Bison C++ parsers], [2002, 2003])[
7548fed2 1081
5d003116
AD
1082/**
1083 ** \file location.hh
1084 ** Define the Location class.
1085 */
7548fed2 1086
5d003116
AD
1087#ifndef BISON_LOCATION_HH
1088# define BISON_LOCATION_HH
1089
1090# include <iostream>
1091# include <string>
1092# include "position.hh"
1093
1094namespace yy
1095{
1096
1097 /** \brief Abstract a Location. */
7548fed2 1098 class Location
2b548aa6 1099 {
5d003116
AD
1100 /** \name Ctor & dtor.
1101 ** \{ */
7548fed2 1102 public:
5d003116
AD
1103 /** \brief Construct a Location. */
1104 Location (void) :
1105 begin (),
1106 end ()
1107 {
1108 }
1109 /** \} */
1110
1111
1112 /** \name Line and Column related manipulators
1113 ** \{ */
1114 public:
1115 /** \brief Reset initial location to final location. */
1116 inline void step (void)
1117 {
1118 begin = end;
1119 }
1120
2ffbee0e
PE
1121 /** \brief Extend the current location to the COUNT next columns. */
1122 inline void columns (unsigned int count = 1)
5d003116 1123 {
2ffbee0e 1124 end += count;
5d003116
AD
1125 }
1126
2ffbee0e
PE
1127 /** \brief Extend the current location to the COUNT next lines. */
1128 inline void lines (unsigned int count = 1)
5d003116 1129 {
2ffbee0e 1130 end.lines (count);
5d003116
AD
1131 }
1132 /** \} */
1133
1134
1135 public:
1136 /** \brief Beginning of the located region. */
7548fed2 1137 Position begin;
5d003116 1138 /** \brief End of the located region. */
7548fed2 1139 Position end;
2b548aa6 1140 };
7548fed2 1141
5d003116
AD
1142 /** \brief Join two Location objects to create a Location. */
1143 inline const Location operator+ (const Location& begin, const Location& end)
1144 {
1145 Location res = begin;
1146 res.end = end.end;
1147 return res;
1148 }
1149
1150 /** \brief Add two Location objects */
1151 inline const Location operator+ (const Location& begin, unsigned width)
1152 {
1153 Location res = begin;
1154 res.columns (width);
1155 return res;
1156 }
7548fed2 1157
5d003116
AD
1158 /** \brief Add and assign a Location */
1159 inline Location &operator+= (Location& res, unsigned width)
1160 {
1161 res.columns (width);
1162 return res;
1163 }
1164
1165 /** \brief Intercept output stream redirection.
1166 ** \param ostr the destination output stream
2cdc240e 1167 ** \param loc a reference to the Location to redirect
5d003116 1168 **
2cdc240e 1169 ** Avoid duplicate information.
5d003116 1170 */
2cdc240e 1171 inline std::ostream& operator<< (std::ostream& ostr, const Location& loc)
7548fed2 1172 {
2cdc240e
AD
1173 Position last = loc.end - 1;
1174 ostr << loc.begin;
1175 if (loc.begin.filename != last.filename)
1176 ostr << '-' << last;
1177 else if (loc.begin.line != last.line)
1178 ostr << '-' << last.line << '.' << last.column;
1179 else if (loc.begin.column != last.column)
1180 ostr << '-' << last.column;
7548fed2
AD
1181 return ostr;
1182 }
1183
2b548aa6
RA
1184}
1185
c5e3e510 1186#endif // not BISON_LOCATION_HH]