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