]>
Commit | Line | Data |
---|---|---|
a75c057f | 1 | m4_divert(-1) |
60491a94 AD |
2 | # C++ skeleton for Bison |
3 | # Copyright (C) 2002 Free Software Foundation, Inc. | |
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 | ||
fb8135fa | 20 | m4_include([c.m4]) |
680e8701 | 21 | |
66d30cd4 AD |
22 | ## ---------------- ## |
23 | ## Default values. ## | |
24 | ## ---------------- ## | |
25 | ||
26 | # Stack parameters. | |
27 | m4_define_default([b4_stack_depth_init], [200]) | |
28 | ||
29 | # Default Parser class name. | |
30 | m4_define_default([b4_parser_class_name], [Parser]) | |
31 | ||
32 | ||
33 | ||
34 | ## ----------------- ## | |
35 | ## Semantic Values. ## | |
36 | ## ----------------- ## | |
37 | ||
38 | ||
82b6cb3f AD |
39 | # b4_lhs_value([TYPE]) |
40 | # -------------------- | |
41 | # Expansion of $<TYPE>$. | |
42 | m4_define([b4_lhs_value], | |
43 | [yyval[]m4_ifval([$1], [.$1])]) | |
44 | ||
45 | ||
46 | # b4_rhs_value(RULE-LENGTH, NUM, [TYPE]) | |
47 | # -------------------------------------- | |
48 | # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH | |
49 | # symbols on RHS. | |
50 | m4_define([b4_rhs_value], | |
6ad762a8 | 51 | [semantic_stack_@{m4_eval([$1 - $2])@}m4_ifval([$3], [.$3])]) |
82b6cb3f | 52 | |
66d30cd4 | 53 | m4_define_default([b4_location_type], [Location]) |
82b6cb3f AD |
54 | |
55 | # b4_lhs_location() | |
56 | # ----------------- | |
57 | # Expansion of @$. | |
58 | m4_define([b4_lhs_location], | |
59 | [yyloc]) | |
60 | ||
61 | ||
62 | # b4_rhs_location(RULE-LENGTH, NUM) | |
63 | # --------------------------------- | |
64 | # Expansion of @NUM, where the current rule has RULE-LENGTH symbols | |
65 | # on RHS. | |
66 | m4_define([b4_rhs_location], | |
6ad762a8 | 67 | [location_stack_@{m4_eval([$1 - $2])@}]) |
82b6cb3f AD |
68 | |
69 | ||
af27eacb | 70 | m4_define([b4_inherit], |
0d8bed56 | 71 | [m4_ifdef([b4_root], |
af27eacb RA |
72 | [: public b4_root |
73 | ], | |
74 | [])]) | |
75 | ||
76 | m4_define([b4_param], | |
77 | [m4_ifdef([b4_root], | |
78 | [, | |
79 | const Param& param], | |
80 | [])]) | |
81 | ||
82 | m4_define([b4_constructor], | |
83 | [m4_ifdef([b4_root], | |
84 | [b4_root (param), | |
85 | ], | |
86 | [])]) | |
87 | ||
98254360 | 88 | |
b526ee61 AD |
89 | # We do want M4 expansion after # for CPP macros. |
90 | m4_changecom() | |
98254360 | 91 | m4_divert(0)dnl |
6ad762a8 | 92 | @output @output_header_name@ |
fb8135fa AD |
93 | b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison], |
94 | [2002]) | |
6ad762a8 PE |
95 | #ifndef YYLSP_NEEDED |
96 | # define YYLSP_NEEDED | |
2b548aa6 RA |
97 | |
98 | #include "stack.hh" | |
2b548aa6 RA |
99 | #include "location.hh" |
100 | ||
8d69a1a3 | 101 | #include <string> |
717be197 | 102 | #include <iostream> |
50997c6e | 103 | |
4162fa07 RA |
104 | /* Using locations. */ |
105 | #define YYLSP_NEEDED b4_locations_flag | |
106 | ||
17acead5 PE |
107 | b4_token_defines(b4_tokens) |
108 | ||
0dd1580a RA |
109 | /* Copy the first part of user declarations. */ |
110 | b4_pre_prologue | |
4162fa07 | 111 | |
e96c9728 | 112 | /* Line __line__ of __file__. */ |
6ad762a8 | 113 | b4_syncline([@oline@], [@ofile@]) |
e96c9728 | 114 | |
69e2658b RA |
115 | /* Enabling traces. */ |
116 | #ifndef YYDEBUG | |
117 | # define YYDEBUG b4_debug | |
118 | #endif | |
119 | ||
120 | /* Enabling verbose error message. */ | |
121 | #ifndef YYERROR_VERBOSE | |
122 | # define YYERROR_VERBOSE b4_error_verbose | |
123 | #endif | |
124 | ||
98254360 | 125 | #ifndef YYSTYPE |
e9955c83 | 126 | m4_ifdef([b4_stype], |
437c2d80 | 127 | [b4_syncline([b4_stype_line], [b4_filename]) |
e96c9728 AD |
128 | typedef union b4_stype yystype; |
129 | /* Line __line__ of __file__. */ | |
6ad762a8 | 130 | b4_syncline([@oline@], [@ofile@])], |
e9955c83 | 131 | [typedef int yystype;]) |
98254360 RA |
132 | # define YYSTYPE yystype |
133 | #endif | |
134 | ||
0dd1580a RA |
135 | /* Copy the second part of user declarations. */ |
136 | b4_post_prologue | |
137 | ||
e96c9728 | 138 | /* Line __line__ of __file__. */ |
6ad762a8 | 139 | b4_syncline([@oline@], [@ofile@]) |
374f5a14 RA |
140 | #ifndef YYLLOC_DEFAULT |
141 | # define YYLLOC_DEFAULT(Current, Rhs, N) \ | |
142 | Current.last_line = Rhs[[N]].last_line; \ | |
143 | Current.last_column = Rhs[[N]].last_column; | |
144 | #endif | |
145 | ||
2b548aa6 RA |
146 | namespace yy |
147 | { | |
66d30cd4 | 148 | class b4_parser_class_name; |
3f3eed27 | 149 | |
2b548aa6 RA |
150 | template < typename P > |
151 | struct Traits | |
152 | { | |
153 | }; | |
154 | ||
155 | template < > | |
66d30cd4 | 156 | struct Traits< b4_parser_class_name > |
2b548aa6 | 157 | { |
a762e609 AD |
158 | typedef b4_int_type_for([b4_translate]) TokenNumberType; |
159 | typedef b4_int_type_for([b4_rhs]) RhsNumberType; | |
50997c6e RA |
160 | typedef int StateType; |
161 | typedef yystype SemanticType; | |
66d30cd4 | 162 | typedef b4_location_type LocationType; |
2b548aa6 RA |
163 | }; |
164 | } | |
165 | ||
2b548aa6 RA |
166 | namespace yy |
167 | { | |
66d30cd4 | 168 | class b4_parser_class_name b4_inherit |
2b548aa6 RA |
169 | { |
170 | public: | |
3f3eed27 | 171 | |
66d30cd4 AD |
172 | typedef Traits< b4_parser_class_name >::TokenNumberType TokenNumberType; |
173 | typedef Traits< b4_parser_class_name >::RhsNumberType RhsNumberType; | |
174 | typedef Traits< b4_parser_class_name >::StateType StateType; | |
175 | typedef Traits< b4_parser_class_name >::SemanticType SemanticType; | |
176 | typedef Traits< b4_parser_class_name >::LocationType LocationType; | |
2b548aa6 RA |
177 | |
178 | typedef Stack< StateType > StateStack; | |
179 | typedef Stack< SemanticType > SemanticStack; | |
180 | typedef Stack< LocationType > LocationStack; | |
181 | ||
8d69a1a3 | 182 | #if YYLSP_NEEDED |
66d30cd4 | 183 | b4_parser_class_name (bool debug, |
0d8bed56 | 184 | LocationType initlocation[]b4_param) : |
af27eacb | 185 | b4_constructor[]debug_ (debug), |
717be197 | 186 | cdebug_ (std::cerr), |
af27eacb | 187 | initlocation_ (initlocation) |
8d69a1a3 | 188 | #else |
66d30cd4 | 189 | b4_parser_class_name (bool debug[]b4_param) : |
717be197 AD |
190 | b4_constructor[]debug_ (debug), |
191 | cdebug_ (std::cerr) | |
8d69a1a3 | 192 | #endif |
50997c6e | 193 | { |
50997c6e RA |
194 | } |
195 | ||
66d30cd4 | 196 | virtual ~b4_parser_class_name () |
2b548aa6 | 197 | { |
2b548aa6 RA |
198 | } |
199 | ||
200 | virtual int parse (); | |
201 | ||
202 | private: | |
3f3eed27 | 203 | |
69e2658b | 204 | virtual void lex_ (); |
4bb2bc3f | 205 | virtual void error_ (); |
4aacc3a7 | 206 | virtual void print_ (); |
4bb2bc3f | 207 | |
2b548aa6 | 208 | /* Stacks. */ |
69e2658b RA |
209 | StateStack state_stack_; |
210 | SemanticStack semantic_stack_; | |
211 | LocationStack location_stack_; | |
2b548aa6 RA |
212 | |
213 | /* Tables. */ | |
a762e609 AD |
214 | static const b4_int_type_for([b4_pact]) pact_[[]]; |
215 | static const b4_int_type_for([b4_pact]) pact_ninf_; | |
216 | static const b4_int_type_for([b4_defact]) defact_[[]]; | |
217 | static const b4_int_type_for([b4_pgoto]) pgoto_[[]]; | |
218 | static const b4_int_type_for([b4_defgoto]) defgoto_[[]]; | |
219 | static const b4_int_type_for([b4_table]) table_[[]]; | |
220 | static const b4_int_type_for([b4_table]) table_ninf_; | |
221 | static const b4_int_type_for([b4_check]) check_[[]]; | |
222 | static const b4_int_type_for([b4_r1]) r1_[[]]; | |
223 | static const b4_int_type_for([b4_r2]) r2_[[]]; | |
69e2658b RA |
224 | |
225 | #if YYDEBUG || YYERROR_VERBOSE | |
3f3eed27 | 226 | static const char* const name_[[]]; |
69e2658b | 227 | #endif |
2b548aa6 RA |
228 | |
229 | /* More tables, for debugging. */ | |
69e2658b | 230 | #if YYDEBUG |
06446ccf | 231 | static const RhsNumberType rhs_[[]]; |
a762e609 AD |
232 | static const b4_int_type_for([b4_prhs]) prhs_[[]]; |
233 | static const b4_int_type_for([b4_rline]) rline_[[]]; | |
234 | static const b4_int_type_for([b4_stos]) stos_[[]]; | |
235 | static const b4_int_type_for([b4_toknum]) token_number_[[]]; | |
69e2658b | 236 | #endif |
2b548aa6 RA |
237 | |
238 | /* Even more tables. */ | |
680e8701 | 239 | static inline TokenNumberType translate_ (int token); |
2b548aa6 | 240 | |
762a801e | 241 | /* Constants. */ |
50997c6e | 242 | static const int eof_; |
39912f52 | 243 | /* LAST_ -- Last index in TABLE_. */ |
69e2658b | 244 | static const int last_; |
69e2658b | 245 | static const int nnts_; |
50997c6e | 246 | static const int empty_; |
69e2658b | 247 | static const int final_; |
762a801e RA |
248 | static const int terror_; |
249 | static const int errcode_; | |
50997c6e | 250 | static const int ntokens_; |
69e2658b | 251 | static const int initdepth_; |
007a50a4 AD |
252 | static const unsigned user_token_number_max_; |
253 | static const TokenNumberType undef_token_; | |
2b548aa6 RA |
254 | |
255 | /* State. */ | |
69e2658b RA |
256 | int n_; |
257 | int len_; | |
69e2658b | 258 | int state_; |
4bb2bc3f | 259 | |
717be197 AD |
260 | /* Debugging. */ |
261 | int debug_; | |
262 | std::ostream &cdebug_; | |
263 | ||
69e2658b RA |
264 | /* Lookahead and lookahead in internal form. */ |
265 | int looka_; | |
266 | int ilooka_; | |
4bb2bc3f RA |
267 | |
268 | /* Message. */ | |
269 | std::string message; | |
270 | ||
374f5a14 | 271 | /* Semantic value and location of lookahead token. */ |
2b548aa6 RA |
272 | SemanticType value; |
273 | LocationType location; | |
8d69a1a3 | 274 | |
6ad762a8 | 275 | /* @@$ and $$. */ |
374f5a14 RA |
276 | SemanticType yyval; |
277 | LocationType yyloc; | |
278 | ||
8d69a1a3 RA |
279 | /* Initial location. */ |
280 | LocationType initlocation_; | |
2b548aa6 RA |
281 | }; |
282 | } | |
283 | ||
6ad762a8 | 284 | #endif /* ! defined YYLSP_NEEDED */ |
21846f69 | 285 | dnl |
6ad762a8 | 286 | @output @output_parser_name@ |
fb8135fa AD |
287 | b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison], |
288 | [2002]) | |
98254360 | 289 | |
6ad762a8 | 290 | #include @output_header_name@ |
50997c6e | 291 | |
2b548aa6 | 292 | /* Enable debugging if requested. */ |
50997c6e | 293 | #if YYDEBUG |
717be197 | 294 | # define YYCDEBUG if (debug_) cdebug_ |
2b548aa6 | 295 | #else /* !YYDEBUG */ |
717be197 | 296 | # define YYCDEBUG if (0) cdebug_ |
2b548aa6 RA |
297 | #endif /* !YYDEBUG */ |
298 | ||
2b548aa6 | 299 | int |
66d30cd4 | 300 | yy::b4_parser_class_name::parse () |
2b548aa6 | 301 | { |
4bb2bc3f RA |
302 | int nerrs = 0; |
303 | int errstatus = 0; | |
304 | ||
2b548aa6 | 305 | /* Initialize stack. */ |
69e2658b RA |
306 | state_stack_ = StateStack (0); |
307 | semantic_stack_ = SemanticStack (1); | |
308 | location_stack_ = LocationStack (1); | |
2b548aa6 | 309 | |
2b548aa6 | 310 | /* Start. */ |
69e2658b RA |
311 | state_ = 0; |
312 | looka_ = empty_; | |
8d69a1a3 RA |
313 | #if YYLSP_NEEDED |
314 | location = initlocation_; | |
315 | #endif | |
717be197 | 316 | YYCDEBUG << "Starting parse" << std::endl; |
2b548aa6 RA |
317 | |
318 | /* New state. */ | |
319 | yynewstate: | |
69e2658b | 320 | state_stack_.push (state_); |
717be197 | 321 | YYCDEBUG << "Entering state " << state_ << std::endl; |
50997c6e | 322 | goto yybackup; |
2b548aa6 RA |
323 | |
324 | /* Backup. */ | |
325 | yybackup: | |
326 | ||
327 | /* Try to take a decision without lookahead. */ | |
69e2658b | 328 | n_ = pact_[[state_]]; |
12b0043a | 329 | if (n_ == pact_ninf_) |
2b548aa6 RA |
330 | goto yydefault; |
331 | ||
332 | /* Read a lookahead token. */ | |
69e2658b | 333 | if (looka_ == empty_) |
2b548aa6 | 334 | { |
717be197 | 335 | YYCDEBUG << "Reading a token: "; |
69e2658b | 336 | lex_ (); |
2b548aa6 RA |
337 | } |
338 | ||
339 | /* Convert token to internal form. */ | |
69e2658b | 340 | if (looka_ <= 0) |
2b548aa6 | 341 | { |
69e2658b RA |
342 | looka_ = eof_; |
343 | ilooka_ = 0; | |
717be197 | 344 | YYCDEBUG << "Now at end of input." << std::endl; |
2b548aa6 RA |
345 | } |
346 | else | |
347 | { | |
69e2658b | 348 | ilooka_ = translate_ (looka_); |
50997c6e RA |
349 | #if YYDEBUG |
350 | if (debug_) | |
351 | { | |
717be197 AD |
352 | YYCDEBUG << "Next token is " << looka_ |
353 | << " (" << name_[[ilooka_]]; | |
4aacc3a7 | 354 | print_ (); |
717be197 | 355 | YYCDEBUG << ')' << std::endl; |
50997c6e | 356 | } |
2b548aa6 RA |
357 | #endif |
358 | } | |
359 | ||
69e2658b | 360 | n_ += ilooka_; |
39912f52 | 361 | if (n_ < 0 || last_ < n_ || check_[[n_]] != ilooka_) |
2b548aa6 RA |
362 | goto yydefault; |
363 | ||
364 | /* Reduce or error. */ | |
69e2658b RA |
365 | n_ = table_[[n_]]; |
366 | if (n_ < 0) | |
2b548aa6 | 367 | { |
12b0043a | 368 | if (n_ == table_ninf_) |
2b548aa6 RA |
369 | goto yyerrlab; |
370 | else | |
371 | { | |
69e2658b | 372 | n_ = -n_; |
2b548aa6 RA |
373 | goto yyreduce; |
374 | } | |
375 | } | |
69e2658b | 376 | else if (n_ == 0) |
2b548aa6 | 377 | goto yyerrlab; |
a75c057f | 378 | |
2b548aa6 | 379 | /* Accept? */ |
69e2658b | 380 | if (n_ == final_) |
2b548aa6 RA |
381 | goto yyacceptlab; |
382 | ||
383 | /* Shift the lookahead token. */ | |
717be197 AD |
384 | YYCDEBUG << "Shifting token " << looka_ |
385 | << " (" << name_[[ilooka_]] << "), "; | |
2b548aa6 RA |
386 | |
387 | /* Discard the token being shifted unless it is eof. */ | |
69e2658b RA |
388 | if (looka_ != eof_) |
389 | looka_ = empty_; | |
2b548aa6 | 390 | |
69e2658b RA |
391 | semantic_stack_.push (value); |
392 | location_stack_.push (location); | |
8d69a1a3 RA |
393 | |
394 | /* Count tokens shifted since error; after three, turn off error | |
395 | status. */ | |
396 | if (errstatus) | |
397 | --errstatus; | |
398 | ||
69e2658b | 399 | state_ = n_; |
2b548aa6 RA |
400 | goto yynewstate; |
401 | ||
402 | /* Default action. */ | |
403 | yydefault: | |
69e2658b RA |
404 | n_ = defact_[[state_]]; |
405 | if (n_ == 0) | |
2b548aa6 | 406 | goto yyerrlab; |
50997c6e | 407 | goto yyreduce; |
2b548aa6 RA |
408 | |
409 | /* Reduce. */ | |
410 | yyreduce: | |
69e2658b RA |
411 | len_ = r2_[[n_]]; |
412 | if (len_) | |
50997c6e | 413 | { |
45119f04 RA |
414 | yyval = semantic_stack_[[len_ - 1]]; |
415 | yyloc = location_stack_[[len_ - 1]]; | |
50997c6e RA |
416 | } |
417 | else | |
69e2658b | 418 | { |
374f5a14 RA |
419 | yyval = semantic_stack_[[0]]; |
420 | yyloc = location_stack_[[0]]; | |
50997c6e | 421 | } |
2b548aa6 | 422 | |
50997c6e RA |
423 | #if YYDEBUG |
424 | if (debug_) | |
2b548aa6 | 425 | { |
717be197 AD |
426 | YYCDEBUG << "Reducing via rule " << n_ - 1 |
427 | << " (line " << rline_[[n_]] << "), "; | |
a762e609 | 428 | for (b4_int_type_for([b4_prhs]) i = prhs_[[n_]]; |
39912f52 | 429 | 0 <= rhs_[[i]]; ++i) |
717be197 AD |
430 | YYCDEBUG << name_[[rhs_[i]]] << ' '; |
431 | YYCDEBUG << "-> " << name_[[r1_[n_]]] << std::endl; | |
2b548aa6 RA |
432 | } |
433 | #endif | |
a75c057f | 434 | |
374f5a14 RA |
435 | if (len_) |
436 | { | |
437 | Slice< LocationType, LocationStack > slice (location_stack_, len_); | |
438 | YYLLOC_DEFAULT (yyloc, slice, len_); | |
439 | } | |
440 | ||
45119f04 RA |
441 | switch (n_) |
442 | { | |
443 | b4_actions | |
444 | } | |
a75c057f | 445 | |
06446ccf | 446 | /* Line __line__ of __file__. */ |
6ad762a8 | 447 | b4_syncline([@oline@], [@ofile@]) |
06446ccf | 448 | |
69e2658b RA |
449 | state_stack_.pop (len_); |
450 | semantic_stack_.pop (len_); | |
451 | location_stack_.pop (len_); | |
2b548aa6 | 452 | |
50997c6e RA |
453 | #if YYDEBUG |
454 | if (debug_) | |
2b548aa6 | 455 | { |
717be197 | 456 | YYCDEBUG << "state stack now"; |
a75c057f | 457 | for (StateStack::ConstIterator i = state_stack_.begin (); |
69e2658b | 458 | i != state_stack_.end (); ++i) |
717be197 AD |
459 | YYCDEBUG << ' ' << *i; |
460 | YYCDEBUG << std::endl; | |
2b548aa6 RA |
461 | } |
462 | #endif | |
a75c057f | 463 | |
374f5a14 RA |
464 | semantic_stack_.push (yyval); |
465 | location_stack_.push (yyloc); | |
2b548aa6 RA |
466 | |
467 | /* Shift the result of the reduction. */ | |
69e2658b RA |
468 | n_ = r1_[[n_]]; |
469 | state_ = pgoto_[[n_ - ntokens_]] + state_stack_[[0]]; | |
39912f52 | 470 | if (0 <= state_ && state_ <= last_ && check_[[state_]] == state_stack_[[0]]) |
69e2658b | 471 | state_ = table_[[state_]]; |
2b548aa6 | 472 | else |
69e2658b | 473 | state_ = defgoto_[[n_ - ntokens_]]; |
2b548aa6 RA |
474 | goto yynewstate; |
475 | ||
476 | /* Report and recover from errors. This is very incomplete. */ | |
477 | yyerrlab: | |
4bb2bc3f RA |
478 | /* If not already recovering from an error, report this error. */ |
479 | if (!errstatus) | |
480 | { | |
481 | ++nerrs; | |
a75c057f | 482 | |
69e2658b RA |
483 | #if YYERROR_VERBOSE |
484 | n_ = pact_[[state_]]; | |
12b0043a | 485 | if (pact_ninf_ < n_ && n_ < last_) |
4bb2bc3f | 486 | { |
6e649e65 | 487 | message = "syntax error, unexpected "; |
69e2658b | 488 | message += name_[[ilooka_]]; |
4bb2bc3f RA |
489 | { |
490 | int count = 0; | |
69e2658b | 491 | for (int x = (n_ < 0 ? -n_ : 0); x < ntokens_ + nnts_; ++x) |
217598da | 492 | if (check_[[x + n_]] == x && x != terror_) |
4bb2bc3f RA |
493 | ++count; |
494 | if (count < 5) | |
495 | { | |
496 | count = 0; | |
69e2658b | 497 | for (int x = (n_ < 0 ? -n_ : 0); x < ntokens_ + nnts_; ++x) |
217598da | 498 | if (check_[[x + n_]] == x && x != terror_) |
4bb2bc3f | 499 | { |
a75c057f | 500 | message += (!count++) ? ", expecting " : " or "; |
4bb2bc3f RA |
501 | message += name_[[x]]; |
502 | } | |
503 | } | |
504 | } | |
505 | } | |
506 | else | |
69e2658b | 507 | #endif |
6e649e65 | 508 | message = "syntax error"; |
8d69a1a3 | 509 | error_ (); |
4bb2bc3f | 510 | } |
762a801e | 511 | goto yyerrlab1; |
a75c057f | 512 | |
762a801e RA |
513 | /* Error raised explicitly by an action. */ |
514 | yyerrlab1: | |
515 | if (errstatus == 3) | |
516 | { | |
517 | /* If just tried and failed to reuse lookahead token after an | |
518 | error, discard it. */ | |
519 | ||
520 | /* Return failure if at end of input. */ | |
69e2658b | 521 | if (looka_ == eof_) |
762a801e | 522 | goto yyabortlab; |
717be197 AD |
523 | YYCDEBUG << "Discarding token " << looka_ |
524 | << " (" << name_[[ilooka_]] << ")." << std::endl; | |
69e2658b | 525 | looka_ = empty_; |
762a801e RA |
526 | } |
527 | ||
528 | /* Else will try to reuse lookahead token after shifting the error | |
529 | token. */ | |
530 | ||
531 | errstatus = 3; | |
762a801e | 532 | |
769b430f AD |
533 | for (;;) |
534 | { | |
535 | n_ = pact_[[state_]]; | |
12b0043a | 536 | if (n_ != pact_ninf_) |
769b430f AD |
537 | { |
538 | n_ += terror_; | |
539 | if (0 <= n_ && n_ <= last_ && check_[[n_]] == terror_) | |
540 | { | |
541 | n_ = table_[[n_]]; | |
542 | if (0 < n_) | |
543 | break; | |
544 | } | |
545 | } | |
546 | ||
547 | /* Pop the current state because it cannot handle the error token. */ | |
548 | if (!state_stack_.height ()) | |
549 | goto yyabortlab; | |
762a801e RA |
550 | |
551 | #if YYDEBUG | |
769b430f AD |
552 | if (debug_) |
553 | { | |
554 | if (stos_[[state_]] < ntokens_) | |
555 | { | |
717be197 AD |
556 | YYCDEBUG << "Error: popping token " |
557 | << token_number_[[stos_[state_]]] | |
558 | << " (" << name_[[stos_[state_]]]; | |
769b430f AD |
559 | # ifdef YYPRINT |
560 | YYPRINT (stderr, token_number_[[stos_[state_]]], | |
561 | semantic_stack_.top ()); | |
562 | # endif | |
717be197 | 563 | YYCDEBUG << ')' << std::endl; |
769b430f AD |
564 | } |
565 | else | |
566 | { | |
717be197 AD |
567 | YYCDEBUG << "Error: popping nonterminal (" |
568 | << name_[[stos_[state_]]] << ')' << std::endl; | |
769b430f AD |
569 | } |
570 | } | |
762a801e RA |
571 | #endif |
572 | ||
769b430f AD |
573 | state_ = (state_stack_.pop (), state_stack_[[0]]); |
574 | semantic_stack_.pop (); | |
575 | location_stack_.pop ();; | |
762a801e | 576 | |
769b430f AD |
577 | #if YYDEBUG |
578 | if (debug_) | |
579 | { | |
717be197 | 580 | YYCDEBUG << "Error: state stack now"; |
769b430f AD |
581 | for (StateStack::ConstIterator i = state_stack_.begin (); |
582 | i != state_stack_.end (); ++i) | |
717be197 AD |
583 | YYCDEBUG << ' ' << *i; |
584 | YYCDEBUG << std::endl; | |
769b430f AD |
585 | } |
586 | #endif | |
762a801e | 587 | } |
762a801e | 588 | |
69e2658b | 589 | if (n_ == final_) |
762a801e RA |
590 | goto yyacceptlab; |
591 | ||
717be197 | 592 | YYCDEBUG << "Shifting error token, "; |
762a801e | 593 | |
69e2658b RA |
594 | semantic_stack_.push (value); |
595 | location_stack_.push (location); | |
762a801e | 596 | |
69e2658b | 597 | state_ = n_; |
762a801e RA |
598 | goto yynewstate; |
599 | ||
2b548aa6 RA |
600 | /* Accept. */ |
601 | yyacceptlab: | |
602 | return 0; | |
762a801e RA |
603 | |
604 | /* Abort. */ | |
605 | yyabortlab: | |
606 | return 1; | |
2b548aa6 RA |
607 | } |
608 | ||
69e2658b | 609 | void |
66d30cd4 | 610 | yy::b4_parser_class_name::lex_ () |
69e2658b RA |
611 | { |
612 | #if YYLSP_NEEDED | |
613 | looka_ = yylex (&value, &location); | |
614 | #else | |
615 | looka_ = yylex (&value); | |
616 | #endif | |
617 | } | |
618 | ||
6b45a3ca | 619 | /* YYPACT[[STATE-NUM]] -- Index in YYTABLE of the portion describing |
2b548aa6 | 620 | STATE-NUM. */ |
66d30cd4 | 621 | const b4_int_type_for([b4_pact]) yy::b4_parser_class_name::pact_ninf_ = b4_pact_ninf; |
a762e609 | 622 | const b4_int_type_for([b4_pact]) |
66d30cd4 | 623 | yy::b4_parser_class_name::pact_[[]] = |
2b548aa6 | 624 | { |
3f3eed27 | 625 | b4_pact |
2b548aa6 RA |
626 | }; |
627 | ||
6b45a3ca | 628 | /* YYDEFACT[[S]] -- default rule to reduce with in state S when YYTABLE |
2b548aa6 RA |
629 | doesn't specify something else to do. Zero means the default is an |
630 | error. */ | |
a762e609 | 631 | const b4_int_type_for([b4_defact]) |
66d30cd4 | 632 | yy::b4_parser_class_name::defact_[[]] = |
2b548aa6 | 633 | { |
3f3eed27 | 634 | b4_defact |
2b548aa6 RA |
635 | }; |
636 | ||
6b45a3ca | 637 | /* YYPGOTO[[NTERM-NUM]]. */ |
a762e609 | 638 | const b4_int_type_for([b4_pgoto]) |
66d30cd4 | 639 | yy::b4_parser_class_name::pgoto_[[]] = |
2b548aa6 | 640 | { |
3f3eed27 | 641 | b4_pgoto |
2b548aa6 RA |
642 | }; |
643 | ||
6b45a3ca | 644 | /* YYDEFGOTO[[NTERM-NUM]]. */ |
a762e609 | 645 | const b4_int_type_for([b4_defgoto]) |
66d30cd4 | 646 | yy::b4_parser_class_name::defgoto_[[]] = |
2b548aa6 | 647 | { |
3f3eed27 | 648 | b4_defgoto |
2b548aa6 RA |
649 | }; |
650 | ||
6b45a3ca | 651 | /* YYTABLE[[YYPACT[STATE-NUM]]]. What to do in state STATE-NUM. If |
2b548aa6 RA |
652 | positive, shift that token. If negative, reduce the rule which |
653 | number is the opposite. If zero, do what YYDEFACT says. */ | |
66d30cd4 | 654 | const b4_int_type_for([b4_table]) yy::b4_parser_class_name::table_ninf_ = b4_table_ninf; |
a762e609 | 655 | const b4_int_type_for([b4_table]) |
66d30cd4 | 656 | yy::b4_parser_class_name::table_[[]] = |
2b548aa6 | 657 | { |
3f3eed27 | 658 | b4_table |
2b548aa6 RA |
659 | }; |
660 | ||
661 | /* YYCHECK. */ | |
a762e609 | 662 | const b4_int_type_for([b4_check]) |
66d30cd4 | 663 | yy::b4_parser_class_name::check_[[]] = |
2b548aa6 | 664 | { |
3f3eed27 | 665 | b4_check |
2b548aa6 RA |
666 | }; |
667 | ||
769b430f AD |
668 | #if YYDEBUG |
669 | /* STOS_[[STATE-NUM]] -- The (internal number of the) accessing | |
670 | symbol of state STATE-NUM. */ | |
a762e609 | 671 | const b4_int_type_for([b4_stos]) |
66d30cd4 | 672 | yy::b4_parser_class_name::stos_[[]] = |
769b430f AD |
673 | { |
674 | b4_stos | |
675 | }; | |
676 | ||
677 | /* TOKEN_NUMBER_[[YYLEX-NUM]] -- Internal token number corresponding | |
678 | to YYLEX-NUM. */ | |
a762e609 | 679 | const b4_int_type_for([b4_toknum]) |
66d30cd4 | 680 | yy::b4_parser_class_name::token_number_[[]] = |
769b430f AD |
681 | { |
682 | b4_toknum | |
683 | }; | |
684 | #endif | |
685 | ||
6b45a3ca | 686 | /* YYR1[[YYN]] -- Symbol number of symbol that rule YYN derives. */ |
a762e609 | 687 | const b4_int_type_for([b4_r1]) |
66d30cd4 | 688 | yy::b4_parser_class_name::r1_[[]] = |
2b548aa6 | 689 | { |
3f3eed27 | 690 | b4_r1 |
2b548aa6 RA |
691 | }; |
692 | ||
6b45a3ca | 693 | /* YYR2[[YYN]] -- Number of symbols composing right hand side of rule YYN. */ |
a762e609 | 694 | const b4_int_type_for([b4_r2]) |
66d30cd4 | 695 | yy::b4_parser_class_name::r2_[[]] = |
2b548aa6 | 696 | { |
3f3eed27 | 697 | b4_r2 |
2b548aa6 RA |
698 | }; |
699 | ||
69e2658b | 700 | #if YYDEBUG || YYERROR_VERBOSE |
6b45a3ca | 701 | /* YYTNAME[[SYMBOL-NUM]] -- String name of the symbol SYMBOL-NUM. |
2b548aa6 RA |
702 | First, the terminals, then, starting at YYNTOKENS, nonterminals. */ |
703 | const char* | |
66d30cd4 | 704 | const yy::b4_parser_class_name::name_[[]] = |
2b548aa6 | 705 | { |
3f3eed27 | 706 | b4_tname |
2b548aa6 | 707 | }; |
69e2658b | 708 | #endif |
2b548aa6 | 709 | |
69e2658b | 710 | #if YYDEBUG |
2b548aa6 | 711 | /* YYRHS -- A `-1'-separated list of the rules' RHS. */ |
66d30cd4 AD |
712 | const yy::b4_parser_class_name::RhsNumberType |
713 | yy::b4_parser_class_name::rhs_[[]] = | |
2b548aa6 | 714 | { |
3f3eed27 | 715 | b4_rhs |
2b548aa6 RA |
716 | }; |
717 | ||
6b45a3ca | 718 | /* YYPRHS[[YYN]] -- Index of the first RHS symbol of rule number YYN in |
2b548aa6 | 719 | YYRHS. */ |
a762e609 | 720 | const b4_int_type_for([b4_prhs]) |
66d30cd4 | 721 | yy::b4_parser_class_name::prhs_[[]] = |
2b548aa6 | 722 | { |
3f3eed27 | 723 | b4_prhs |
2b548aa6 RA |
724 | }; |
725 | ||
69e2658b | 726 | /* YYRLINE[[YYN]] -- source line where rule number YYN was defined. */ |
a762e609 | 727 | const b4_int_type_for([b4_rline]) |
66d30cd4 | 728 | yy::b4_parser_class_name::rline_[[]] = |
69e2658b RA |
729 | { |
730 | b4_rline | |
731 | }; | |
732 | #endif | |
733 | ||
2b548aa6 | 734 | /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ |
66d30cd4 AD |
735 | yy::b4_parser_class_name::TokenNumberType |
736 | yy::b4_parser_class_name::translate_ (int token) | |
2b548aa6 | 737 | { |
a75c057f | 738 | static |
680e8701 | 739 | const TokenNumberType |
3f3eed27 | 740 | translate_[[]] = |
2b548aa6 | 741 | { |
3f3eed27 | 742 | b4_translate |
2b548aa6 | 743 | }; |
007a50a4 AD |
744 | if ((unsigned) token <= user_token_number_max_) |
745 | return translate_[[token]]; | |
746 | else | |
747 | return undef_token_; | |
2b548aa6 RA |
748 | } |
749 | ||
66d30cd4 AD |
750 | const int yy::b4_parser_class_name::eof_ = 0; |
751 | const int yy::b4_parser_class_name::last_ = b4_last; | |
752 | const int yy::b4_parser_class_name::nnts_ = b4_nterms_number; | |
753 | const int yy::b4_parser_class_name::empty_ = -2; | |
754 | const int yy::b4_parser_class_name::final_ = b4_final_state_number; | |
755 | const int yy::b4_parser_class_name::terror_ = 1; | |
756 | const int yy::b4_parser_class_name::errcode_ = 256; | |
757 | const int yy::b4_parser_class_name::ntokens_ = b4_tokens_number; | |
758 | const int yy::b4_parser_class_name::initdepth_ = b4_stack_depth_init; | |
759 | ||
760 | const unsigned yy::b4_parser_class_name::user_token_number_max_ = b4_user_token_number_max; | |
f1886bb2 | 761 | const yy::b4_parser_class_name::TokenNumberType yy::b4_parser_class_name::undef_token_ = b4_undef_token_number; |
2b548aa6 | 762 | |
3f3eed27 | 763 | b4_epilogue |
21846f69 | 764 | dnl |
6ad762a8 | 765 | @output stack.hh |
fb8135fa | 766 | b4_copyright([2002]) |
98254360 | 767 | |
2b548aa6 RA |
768 | #ifndef BISON_STACK_HH |
769 | # define BISON_STACK_HH | |
770 | ||
45119f04 | 771 | #include <deque> |
2b548aa6 RA |
772 | |
773 | namespace yy | |
774 | { | |
45119f04 | 775 | template < class T, class S = std::deque< T > > |
2b548aa6 RA |
776 | class Stack |
777 | { | |
778 | public: | |
779 | ||
780 | typedef typename S::iterator Iterator; | |
781 | typedef typename S::const_iterator ConstIterator; | |
782 | ||
783 | Stack () : seq_ () | |
784 | { | |
785 | } | |
786 | ||
787 | Stack (unsigned n) : seq_ (n) | |
788 | { | |
789 | } | |
790 | ||
791 | inline | |
792 | T& | |
45119f04 | 793 | operator [[]] (unsigned index) |
2b548aa6 | 794 | { |
45119f04 | 795 | return seq_[[index]]; |
2b548aa6 RA |
796 | } |
797 | ||
798 | inline | |
799 | const T& | |
45119f04 | 800 | operator [[]] (unsigned index) const |
2b548aa6 | 801 | { |
45119f04 | 802 | return seq_[[index]]; |
2b548aa6 RA |
803 | } |
804 | ||
805 | inline | |
806 | void | |
807 | push (const T& t) | |
808 | { | |
45119f04 | 809 | seq_.push_front (t); |
2b548aa6 RA |
810 | } |
811 | ||
812 | inline | |
813 | void | |
814 | pop (unsigned n = 1) | |
815 | { | |
816 | for (; n; --n) | |
45119f04 | 817 | seq_.pop_front (); |
2b548aa6 RA |
818 | } |
819 | ||
762a801e RA |
820 | inline |
821 | unsigned | |
822 | height () const | |
823 | { | |
824 | return seq_.size (); | |
825 | } | |
826 | ||
2b548aa6 RA |
827 | inline ConstIterator begin () const { return seq_.begin (); } |
828 | inline ConstIterator end () const { return seq_.end (); } | |
829 | ||
830 | private: | |
831 | ||
832 | S seq_; | |
833 | }; | |
374f5a14 RA |
834 | |
835 | template < class T, class S = Stack< T > > | |
836 | class Slice | |
837 | { | |
838 | public: | |
839 | ||
840 | Slice (const S& stack, | |
841 | unsigned range) : stack_ (stack), | |
842 | range_ (range) | |
843 | { | |
844 | } | |
845 | ||
846 | inline | |
847 | const T& | |
848 | operator [[]] (unsigned index) const | |
849 | { | |
45119f04 | 850 | return stack_[[range_ - index]]; |
374f5a14 RA |
851 | } |
852 | ||
853 | private: | |
854 | ||
855 | const S& stack_; | |
856 | unsigned range_; | |
857 | }; | |
2b548aa6 RA |
858 | } |
859 | ||
860 | #endif // not BISON_STACK_HH | |
21846f69 | 861 | dnl |
6ad762a8 | 862 | @output location.hh |
fb8135fa | 863 | b4_copyright([2002]) |
98254360 | 864 | |
2b548aa6 RA |
865 | #ifndef BISON_LOCATION_HH |
866 | # define BISON_LOCATION_HH | |
867 | ||
868 | namespace yy | |
869 | { | |
870 | struct Position | |
871 | { | |
872 | int line; | |
873 | int column; | |
874 | }; | |
875 | ||
876 | struct Location | |
877 | { | |
878 | Position first; | |
879 | Position last; | |
880 | }; | |
881 | } | |
882 | ||
883 | #endif // not BISON_LOCATION_HH |