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