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