]> git.saurik.com Git - bison.git/blame - data/lalr1.cc
* data/lalr1.cc (translate_, destruct_): No reason to be static.
[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:
762a801e 717 return 1;
2b548aa6
RA
718}
719
69e2658b 720void
c5e3e510 721yy::]b4_parser_class_name[::lex_ ()
69e2658b
RA
722{
723#if YYLSP_NEEDED
724 looka_ = yylex (&value, &location);
725#else
726 looka_ = yylex (&value);
727#endif
728}
729
a08460b0
AD
730/** Generate an error message, and invoke yyerror. */
731void
732yy::]b4_parser_class_name[::report_syntax_error_ ()
733{
734 /* If not already recovering from an error, report this error. */
735 if (!errstatus_)
736 {
737 ++nerrs_;
738
739#if YYERROR_VERBOSE
740 n_ = pact_[state_];
741 if (pact_ninf_ < n_ && n_ < last_)
742 {
743 message = "syntax error, unexpected ";
744 message += name_[ilooka_];
745 {
746 int count = 0;
747 for (int x = (n_ < 0 ? -n_ : 0); x < ntokens_ + nnts_; ++x)
748 if (check_[x + n_] == x && x != terror_)
749 ++count;
750 if (count < 5)
751 {
752 count = 0;
753 for (int x = (n_ < 0 ? -n_ : 0); x < ntokens_ + nnts_; ++x)
754 if (check_[x + n_] == x && x != terror_)
755 {
756 message += (!count++) ? ", expecting " : " or ";
757 message += name_[x];
758 }
759 }
760 }
761 }
762 else
763#endif
764 message = "syntax error";
765 error_ ();
766 }
767}
768
5348bfbe 769
c5e3e510 770/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
2b548aa6 771 STATE-NUM. */
0c3c1f98 772const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) yy::b4_parser_class_name::pact_ninf_ = b4_pact_ninf[;
c5e3e510
AD
773const ]b4_int_type_for([b4_pact])[
774yy::]b4_parser_class_name[::pact_[] =
2b548aa6 775{
c5e3e510 776 ]b4_pact[
2b548aa6
RA
777};
778
c5e3e510 779/* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
2b548aa6
RA
780 doesn't specify something else to do. Zero means the default is an
781 error. */
c5e3e510
AD
782const ]b4_int_type_for([b4_defact])[
783yy::]b4_parser_class_name[::defact_[] =
2b548aa6 784{
c5e3e510 785 ]b4_defact[
2b548aa6
RA
786};
787
c5e3e510
AD
788/* YYPGOTO[NTERM-NUM]. */
789const ]b4_int_type_for([b4_pgoto])[
790yy::]b4_parser_class_name[::pgoto_[] =
2b548aa6 791{
c5e3e510 792 ]b4_pgoto[
2b548aa6
RA
793};
794
c5e3e510
AD
795/* YYDEFGOTO[NTERM-NUM]. */
796const ]b4_int_type_for([b4_defgoto])[
797yy::]b4_parser_class_name[::defgoto_[] =
2b548aa6 798{
c5e3e510 799 ]b4_defgoto[
2b548aa6
RA
800};
801
c5e3e510 802/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
2b548aa6
RA
803 positive, shift that token. If negative, reduce the rule which
804 number is the opposite. If zero, do what YYDEFACT says. */
0c3c1f98 805const ]b4_int_type(b4_table_ninf, b4_table_ninf) yy::b4_parser_class_name::table_ninf_ = b4_table_ninf[;
c5e3e510
AD
806const ]b4_int_type_for([b4_table])[
807yy::]b4_parser_class_name[::table_[] =
2b548aa6 808{
c5e3e510 809 ]b4_table[
2b548aa6
RA
810};
811
812/* YYCHECK. */
c5e3e510
AD
813const ]b4_int_type_for([b4_check])[
814yy::]b4_parser_class_name[::check_[] =
2b548aa6 815{
c5e3e510 816 ]b4_check[
2b548aa6
RA
817};
818
c5e3e510 819/* STOS_[STATE-NUM] -- The (internal number of the) accessing
769b430f 820 symbol of state STATE-NUM. */
c5e3e510
AD
821const ]b4_int_type_for([b4_stos])[
822yy::]b4_parser_class_name[::stos_[] =
769b430f 823{
c5e3e510 824 ]b4_stos[
769b430f
AD
825};
826
45d5982f 827#if YYDEBUG
c5e3e510 828/* TOKEN_NUMBER_[YYLEX-NUM] -- Internal token number corresponding
769b430f 829 to YYLEX-NUM. */
c5e3e510
AD
830const ]b4_int_type_for([b4_toknum])[
831yy::]b4_parser_class_name[::token_number_[] =
769b430f 832{
c5e3e510 833 ]b4_toknum[
769b430f
AD
834};
835#endif
836
c5e3e510
AD
837/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
838const ]b4_int_type_for([b4_r1])[
839yy::]b4_parser_class_name[::r1_[] =
2b548aa6 840{
c5e3e510 841 ]b4_r1[
2b548aa6
RA
842};
843
c5e3e510
AD
844/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
845const ]b4_int_type_for([b4_r2])[
846yy::]b4_parser_class_name[::r2_[] =
2b548aa6 847{
c5e3e510 848 ]b4_r2[
2b548aa6
RA
849};
850
69e2658b 851#if YYDEBUG || YYERROR_VERBOSE
c5e3e510 852/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
a5eb1ed2 853 First, the terminals, then, starting at NTOKENS_, nonterminals. */
2b548aa6 854const char*
c5e3e510 855const yy::]b4_parser_class_name[::name_[] =
2b548aa6 856{
c5e3e510 857 ]b4_tname[
2b548aa6 858};
69e2658b 859#endif
2b548aa6 860
69e2658b 861#if YYDEBUG
2b548aa6 862/* YYRHS -- A `-1'-separated list of the rules' RHS. */
c5e3e510
AD
863const yy::]b4_parser_class_name[::RhsNumberType
864yy::]b4_parser_class_name[::rhs_[] =
2b548aa6 865{
c5e3e510 866 ]b4_rhs[
2b548aa6
RA
867};
868
c5e3e510 869/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
2b548aa6 870 YYRHS. */
c5e3e510
AD
871const ]b4_int_type_for([b4_prhs])[
872yy::]b4_parser_class_name[::prhs_[] =
2b548aa6 873{
c5e3e510 874 ]b4_prhs[
2b548aa6
RA
875};
876
c5e3e510
AD
877/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
878const ]b4_int_type_for([b4_rline])[
879yy::]b4_parser_class_name[::rline_[] =
69e2658b 880{
c5e3e510 881 ]b4_rline[
69e2658b 882};
5348bfbe 883
25f66e1a
AD
884/** Print the state stack from its BOTTOM up to its TOP (included). */
885
886void
887yy::]b4_parser_class_name[::stack_print_ ()
888{
889 cdebug_ << "state stack now";
890 for (StateStack::ConstIterator i = state_stack_.begin ();
891 i != state_stack_.end (); ++i)
892 cdebug_ << ' ' << *i;
893 cdebug_ << std::endl;
894}
895
5348bfbe
AD
896/** Report that the YYRULE is going to be reduced. */
897
898void
899yy::]b4_parser_class_name[::reduce_print_ (int yyrule)
900{
5348bfbe
AD
901 unsigned int yylno = rline_[yyrule];
902 /* Print the symbols being reduced, and their result. */
903 cdebug_ << "Reducing via rule " << n_ - 1 << " (line " << yylno << "), ";
904 for (]b4_int_type_for([b4_prhs])[ i = prhs_[n_];
905 0 <= rhs_[i]; ++i)
906 cdebug_ << name_[rhs_[i]] << ' ';
907 cdebug_ << "-> " << name_[r1_[n_]] << std::endl;
908}
909#endif // YYDEBUG
69e2658b 910
2b548aa6 911/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
c5e3e510
AD
912yy::]b4_parser_class_name[::TokenNumberType
913yy::]b4_parser_class_name[::translate_ (int token)
2b548aa6 914{
a75c057f 915 static
680e8701 916 const TokenNumberType
1d4055aa 917 translate_table[] =
2b548aa6 918 {
c5e3e510 919 ]b4_translate[
2b548aa6 920 };
779e7ceb 921 if ((unsigned int) token <= user_token_number_max_)
1d4055aa 922 return translate_table[token];
007a50a4
AD
923 else
924 return undef_token_;
2b548aa6
RA
925}
926
c5e3e510
AD
927const int yy::]b4_parser_class_name[::eof_ = 0;
928const int yy::]b4_parser_class_name[::last_ = ]b4_last[;
929const int yy::]b4_parser_class_name[::nnts_ = ]b4_nterms_number[;
930const int yy::]b4_parser_class_name[::empty_ = -2;
931const int yy::]b4_parser_class_name[::final_ = ]b4_final_state_number[;
932const int yy::]b4_parser_class_name[::terror_ = 1;
933const int yy::]b4_parser_class_name[::errcode_ = 256;
934const int yy::]b4_parser_class_name[::ntokens_ = ]b4_tokens_number[;
66d30cd4 935
779e7ceb 936const unsigned int yy::]b4_parser_class_name[::user_token_number_max_ = ]b4_user_token_number_max[;
c5e3e510 937const yy::]b4_parser_class_name[::TokenNumberType yy::]b4_parser_class_name[::undef_token_ = ]b4_undef_token_number[;
2b548aa6 938
c5e3e510 939]b4_epilogue
21846f69 940dnl
6ad762a8 941@output stack.hh
779e7ceb 942b4_copyright([Stack handling for Bison C++ parsers], [2002, 2003, 2004])[
98254360 943
2b548aa6
RA
944#ifndef BISON_STACK_HH
945# define BISON_STACK_HH
946
45119f04 947#include <deque>
2b548aa6
RA
948
949namespace yy
950{
45119f04 951 template < class T, class S = std::deque< T > >
2b548aa6
RA
952 class Stack
953 {
954 public:
955
956 typedef typename S::iterator Iterator;
957 typedef typename S::const_iterator ConstIterator;
958
959 Stack () : seq_ ()
960 {
961 }
962
779e7ceb 963 Stack (unsigned int n) : seq_ (n)
2b548aa6
RA
964 {
965 }
966
967 inline
968 T&
779e7ceb 969 operator [] (unsigned int i)
2b548aa6 970 {
1d4055aa 971 return seq_[i];
2b548aa6
RA
972 }
973
974 inline
975 const T&
779e7ceb 976 operator [] (unsigned int i) const
2b548aa6 977 {
1d4055aa 978 return seq_[i];
2b548aa6
RA
979 }
980
981 inline
982 void
983 push (const T& t)
984 {
45119f04 985 seq_.push_front (t);
2b548aa6
RA
986 }
987
988 inline
989 void
779e7ceb 990 pop (unsigned int n = 1)
2b548aa6
RA
991 {
992 for (; n; --n)
45119f04 993 seq_.pop_front ();
2b548aa6
RA
994 }
995
762a801e 996 inline
779e7ceb 997 unsigned int
762a801e
RA
998 height () const
999 {
1000 return seq_.size ();
1001 }
1002
2b548aa6
RA
1003 inline ConstIterator begin () const { return seq_.begin (); }
1004 inline ConstIterator end () const { return seq_.end (); }
1005
1006 private:
1007
1008 S seq_;
1009 };
374f5a14
RA
1010
1011 template < class T, class S = Stack< T > >
1012 class Slice
1013 {
1014 public:
1015
1016 Slice (const S& stack,
779e7ceb
PE
1017 unsigned int range) : stack_ (stack),
1018 range_ (range)
374f5a14
RA
1019 {
1020 }
1021
1022 inline
1023 const T&
779e7ceb 1024 operator [] (unsigned int i) const
374f5a14 1025 {
1d4055aa 1026 return stack_[range_ - i];
374f5a14
RA
1027 }
1028
1029 private:
1030
1031 const S& stack_;
779e7ceb 1032 unsigned int range_;
374f5a14 1033 };
2b548aa6
RA
1034}
1035
c5e3e510 1036#endif // not BISON_STACK_HH]
21846f69 1037dnl
5d003116 1038@output position.hh
779e7ceb 1039b4_copyright([Position class for Bison C++ parsers], [2002, 2003, 2004])[
98254360 1040
5d003116
AD
1041/**
1042 ** \file position.hh
1043 ** Define the Location class.
1044 */
1045
1046#ifndef BISON_POSITION_HH
1047# define BISON_POSITION_HH
2b548aa6 1048
7548fed2
AD
1049# include <iostream>
1050# include <string>
1051
2b548aa6
RA
1052namespace yy
1053{
5d003116 1054 /** \brief Abstract a Position. */
7548fed2 1055 class Position
2b548aa6 1056 {
7548fed2 1057 public:
5d003116
AD
1058 /** \brief Initial column number. */
1059 static const unsigned int initial_column = 0;
1060 /** \brief Initial line number. */
1061 static const unsigned int initial_line = 1;
1062
1063 /** \name Ctor & dtor.
1064 ** \{ */
1065 public:
1066 /** \brief Construct a Position. */
1067 Position () :
1068 filename (),
1069 line (initial_line),
1070 column (initial_column)
1071 {
1072 }
1073 /** \} */
1074
7548fed2 1075
5d003116
AD
1076 /** \name Line and Column related manipulators
1077 ** \{ */
1078 public:
2ffbee0e
PE
1079 /** \brief (line related) Advance to the COUNT next lines. */
1080 inline void lines (int count = 1)
5d003116
AD
1081 {
1082 column = initial_column;
2ffbee0e 1083 line += count;
5d003116
AD
1084 }
1085
2ffbee0e
PE
1086 /** \brief (column related) Advance to the COUNT next columns. */
1087 inline void columns (int count = 1)
5d003116 1088 {
f939fc12
AD
1089 int leftmost = initial_column;
1090 int current = column;
2ffbee0e
PE
1091 if (leftmost <= current + count)
1092 column += count;
2cdc240e
AD
1093 else
1094 column = initial_column;
5d003116
AD
1095 }
1096 /** \} */
1097
1098 public:
1099 /** \brief File name to which this position refers. */
7548fed2 1100 std::string filename;
5d003116
AD
1101 /** \brief Current line number. */
1102 unsigned int line;
1103 /** \brief Current column number. */
1104 unsigned int column;
2b548aa6
RA
1105 };
1106
5d003116
AD
1107 /** \brief Add and assign a Position. */
1108 inline const Position&
1109 operator+= (Position& res, const int width)
1110 {
1111 res.columns (width);
1112 return res;
1113 }
1114
1115 /** \brief Add two Position objects. */
1116 inline const Position
1117 operator+ (const Position& begin, const int width)
1118 {
1119 Position res = begin;
1120 return res += width;
1121 }
1122
1123 /** \brief Add and assign a Position. */
1124 inline const Position&
1125 operator-= (Position& res, const int width)
1126 {
1127 return res += -width;
1128 }
1129
1130 /** \brief Add two Position objects. */
1131 inline const Position
1132 operator- (const Position& begin, const int width)
1133 {
1134 return begin + -width;
1135 }
1136
1137 /** \brief Intercept output stream redirection.
1138 ** \param ostr the destination output stream
1139 ** \param pos a reference to the Position to redirect
1140 */
7548fed2
AD
1141 inline std::ostream&
1142 operator<< (std::ostream& ostr, const Position& pos)
1143 {
b81a6e01 1144 if (!pos.filename.empty ())
7548fed2 1145 ostr << pos.filename << ':';
5d003116 1146 return ostr << pos.line << '.' << pos.column;
7548fed2
AD
1147 }
1148
5d003116
AD
1149}
1150#endif // not BISON_POSITION_HH]
1151@output location.hh
779e7ceb 1152b4_copyright([Location class for Bison C++ parsers], [2002, 2003, 2004])[
7548fed2 1153
5d003116
AD
1154/**
1155 ** \file location.hh
1156 ** Define the Location class.
1157 */
7548fed2 1158
5d003116
AD
1159#ifndef BISON_LOCATION_HH
1160# define BISON_LOCATION_HH
1161
1162# include <iostream>
1163# include <string>
1164# include "position.hh"
1165
1166namespace yy
1167{
1168
1169 /** \brief Abstract a Location. */
7548fed2 1170 class Location
2b548aa6 1171 {
5d003116
AD
1172 /** \name Ctor & dtor.
1173 ** \{ */
7548fed2 1174 public:
5d003116
AD
1175 /** \brief Construct a Location. */
1176 Location (void) :
1177 begin (),
1178 end ()
1179 {
1180 }
1181 /** \} */
1182
1183
1184 /** \name Line and Column related manipulators
1185 ** \{ */
1186 public:
1187 /** \brief Reset initial location to final location. */
1188 inline void step (void)
1189 {
1190 begin = end;
1191 }
1192
2ffbee0e
PE
1193 /** \brief Extend the current location to the COUNT next columns. */
1194 inline void columns (unsigned int count = 1)
5d003116 1195 {
2ffbee0e 1196 end += count;
5d003116
AD
1197 }
1198
2ffbee0e
PE
1199 /** \brief Extend the current location to the COUNT next lines. */
1200 inline void lines (unsigned int count = 1)
5d003116 1201 {
2ffbee0e 1202 end.lines (count);
5d003116
AD
1203 }
1204 /** \} */
1205
1206
1207 public:
1208 /** \brief Beginning of the located region. */
7548fed2 1209 Position begin;
5d003116 1210 /** \brief End of the located region. */
7548fed2 1211 Position end;
2b548aa6 1212 };
7548fed2 1213
5d003116
AD
1214 /** \brief Join two Location objects to create a Location. */
1215 inline const Location operator+ (const Location& begin, const Location& end)
1216 {
1217 Location res = begin;
1218 res.end = end.end;
1219 return res;
1220 }
1221
1222 /** \brief Add two Location objects */
779e7ceb 1223 inline const Location operator+ (const Location& begin, unsigned int width)
5d003116
AD
1224 {
1225 Location res = begin;
1226 res.columns (width);
1227 return res;
1228 }
7548fed2 1229
5d003116 1230 /** \brief Add and assign a Location */
779e7ceb 1231 inline Location &operator+= (Location& res, unsigned int width)
5d003116
AD
1232 {
1233 res.columns (width);
1234 return res;
1235 }
1236
1237 /** \brief Intercept output stream redirection.
1238 ** \param ostr the destination output stream
2cdc240e 1239 ** \param loc a reference to the Location to redirect
5d003116 1240 **
2cdc240e 1241 ** Avoid duplicate information.
5d003116 1242 */
2cdc240e 1243 inline std::ostream& operator<< (std::ostream& ostr, const Location& loc)
7548fed2 1244 {
2cdc240e
AD
1245 Position last = loc.end - 1;
1246 ostr << loc.begin;
1247 if (loc.begin.filename != last.filename)
1248 ostr << '-' << last;
1249 else if (loc.begin.line != last.line)
1250 ostr << '-' << last.line << '.' << last.column;
1251 else if (loc.begin.column != last.column)
1252 ostr << '-' << last.column;
7548fed2
AD
1253 return ostr;
1254 }
1255
2b548aa6
RA
1256}
1257
c5e3e510 1258#endif // not BISON_LOCATION_HH]