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