]>
Commit | Line | Data |
---|---|---|
a75c057f | 1 | m4_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. |
25 | m4_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>$. | |
37 | m4_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. | |
45 | m4_define([b4_rhs_value], | |
6ad762a8 | 46 | [semantic_stack_@{m4_eval([$1 - $2])@}m4_ifval([$3], [.$3])]) |
82b6cb3f | 47 | |
66d30cd4 | 48 | m4_define_default([b4_location_type], [Location]) |
82b6cb3f AD |
49 | |
50 | # b4_lhs_location() | |
51 | # ----------------- | |
52 | # Expansion of @$. | |
53 | m4_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. | |
61 | m4_define([b4_rhs_location], | |
6ad762a8 | 62 | [location_stack_@{m4_eval([$1 - $2])@}]) |
82b6cb3f AD |
63 | |
64 | ||
af27eacb | 65 | m4_define([b4_inherit], |
0d8bed56 | 66 | [m4_ifdef([b4_root], |
af27eacb RA |
67 | [: public b4_root |
68 | ], | |
69 | [])]) | |
70 | ||
71 | m4_define([b4_param], | |
72 | [m4_ifdef([b4_root], | |
73 | [, | |
74 | const Param& param], | |
75 | [])]) | |
76 | ||
77 | m4_define([b4_constructor], | |
78 | [m4_ifdef([b4_root], | |
79 | [b4_root (param), | |
80 | ], | |
81 | [])]) | |
82 | ||
98254360 | 83 | |
b526ee61 AD |
84 | # We do want M4 expansion after # for CPP macros. |
85 | m4_changecom() | |
98254360 | 86 | m4_divert(0)dnl |
b61c6978 PE |
87 | m4_if(b4_defines_flag, 0, [], |
88 | [@output @output_header_name@ | |
fb8135fa | 89 | b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison], |
b61c6978 | 90 | [2002, 2003])[ |
c5e3e510 AD |
91 | /* FIXME: This is wrong, we want computed header guards. |
92 | I don't know why the macros are missing now. :( */ | |
93 | #ifndef PARSER_HEADER_H | |
94 | # define PARSER_HEADER_H | |
2b548aa6 RA |
95 | |
96 | #include "stack.hh" | |
2b548aa6 RA |
97 | #include "location.hh" |
98 | ||
8d69a1a3 | 99 | #include <string> |
717be197 | 100 | #include <iostream> |
50997c6e | 101 | |
4162fa07 | 102 | /* Using locations. */ |
c5e3e510 | 103 | #define YYLSP_NEEDED ]b4_locations_flag[ |
4162fa07 | 104 | |
c5e3e510 | 105 | ]b4_token_defines(b4_tokens)[ |
17acead5 | 106 | |
0dd1580a | 107 | /* Copy the first part of user declarations. */ |
c5e3e510 | 108 | ]b4_pre_prologue[ |
4162fa07 | 109 | |
996b1c7e | 110 | ]/* Line __line__ of lalr1.cc. */ |
c5e3e510 | 111 | b4_syncline([@oline@], [@ofile@])[ |
e96c9728 | 112 | |
69e2658b RA |
113 | /* Enabling traces. */ |
114 | #ifndef YYDEBUG | |
c5e3e510 | 115 | # define YYDEBUG ]b4_debug[ |
69e2658b RA |
116 | #endif |
117 | ||
118 | /* Enabling verbose error message. */ | |
119 | #ifndef YYERROR_VERBOSE | |
c5e3e510 | 120 | # define YYERROR_VERBOSE ]b4_error_verbose[ |
69e2658b RA |
121 | #endif |
122 | ||
98254360 | 123 | #ifndef YYSTYPE |
c5e3e510 | 124 | ]m4_ifdef([b4_stype], |
437c2d80 | 125 | [b4_syncline([b4_stype_line], [b4_filename]) |
e96c9728 | 126 | typedef union b4_stype yystype; |
996b1c7e | 127 | /* Line __line__ of lalr1.cc. */ |
6ad762a8 | 128 | b4_syncline([@oline@], [@ofile@])], |
c5e3e510 | 129 | [typedef int yystype;])[ |
98254360 RA |
130 | # define YYSTYPE yystype |
131 | #endif | |
132 | ||
0dd1580a | 133 | /* Copy the second part of user declarations. */ |
c5e3e510 | 134 | ]b4_post_prologue[ |
0dd1580a | 135 | |
996b1c7e | 136 | ]/* Line __line__ of lalr1.cc. */ |
c5e3e510 | 137 | b4_syncline([@oline@], [@ofile@])[ |
374f5a14 RA |
138 | #ifndef YYLLOC_DEFAULT |
139 | # define YYLLOC_DEFAULT(Current, Rhs, N) \ | |
7548fed2 | 140 | Current.end = Rhs[N].end; |
374f5a14 RA |
141 | #endif |
142 | ||
2b548aa6 RA |
143 | namespace yy |
144 | { | |
c5e3e510 | 145 | class ]b4_parser_class_name[; |
3f3eed27 | 146 | |
2b548aa6 RA |
147 | template < typename P > |
148 | struct Traits | |
149 | { | |
150 | }; | |
151 | ||
152 | template < > | |
c5e3e510 | 153 | struct Traits< ]b4_parser_class_name[ > |
2b548aa6 | 154 | { |
c5e3e510 AD |
155 | typedef ]b4_int_type_for([b4_translate])[ TokenNumberType; |
156 | typedef ]b4_int_type_for([b4_rhs])[ RhsNumberType; | |
50997c6e RA |
157 | typedef int StateType; |
158 | typedef yystype SemanticType; | |
c5e3e510 | 159 | typedef ]b4_location_type[ LocationType; |
2b548aa6 RA |
160 | }; |
161 | } | |
162 | ||
2b548aa6 RA |
163 | namespace yy |
164 | { | |
c5e3e510 | 165 | class ]b4_parser_class_name b4_inherit[ |
2b548aa6 RA |
166 | { |
167 | public: | |
3f3eed27 | 168 | |
c5e3e510 AD |
169 | typedef Traits< ]b4_parser_class_name[ >::TokenNumberType TokenNumberType; |
170 | typedef Traits< ]b4_parser_class_name[ >::RhsNumberType RhsNumberType; | |
171 | typedef Traits< ]b4_parser_class_name[ >::StateType StateType; | |
172 | typedef Traits< ]b4_parser_class_name[ >::SemanticType SemanticType; | |
173 | typedef Traits< ]b4_parser_class_name[ >::LocationType LocationType; | |
2b548aa6 RA |
174 | |
175 | typedef Stack< StateType > StateStack; | |
176 | typedef Stack< SemanticType > SemanticStack; | |
177 | typedef Stack< LocationType > LocationStack; | |
178 | ||
8d69a1a3 | 179 | #if YYLSP_NEEDED |
c5e3e510 AD |
180 | ]b4_parser_class_name[ (bool debug, |
181 | LocationType initlocation][]b4_param[) : | |
182 | ]b4_constructor[][debug_ (debug), | |
717be197 | 183 | cdebug_ (std::cerr), |
af27eacb | 184 | initlocation_ (initlocation) |
8d69a1a3 | 185 | #else |
c5e3e510 AD |
186 | ]b4_parser_class_name[ (bool debug][]b4_param[) : |
187 | ]b4_constructor[][debug_ (debug), | |
717be197 | 188 | cdebug_ (std::cerr) |
8d69a1a3 | 189 | #endif |
50997c6e | 190 | { |
50997c6e RA |
191 | } |
192 | ||
c5e3e510 | 193 | virtual ~]b4_parser_class_name[ () |
2b548aa6 | 194 | { |
2b548aa6 RA |
195 | } |
196 | ||
197 | virtual int parse (); | |
198 | ||
199 | private: | |
3f3eed27 | 200 | |
69e2658b | 201 | virtual void lex_ (); |
4bb2bc3f | 202 | virtual void error_ (); |
4aacc3a7 | 203 | virtual void print_ (); |
4bb2bc3f | 204 | |
2b548aa6 | 205 | /* Stacks. */ |
69e2658b RA |
206 | StateStack state_stack_; |
207 | SemanticStack semantic_stack_; | |
208 | LocationStack location_stack_; | |
2b548aa6 RA |
209 | |
210 | /* Tables. */ | |
c5e3e510 AD |
211 | static const ]b4_int_type_for([b4_pact])[ pact_[]; |
212 | static const ]b4_int_type_for([b4_pact])[ pact_ninf_; | |
213 | static const ]b4_int_type_for([b4_defact])[ defact_[]; | |
214 | static const ]b4_int_type_for([b4_pgoto])[ pgoto_[]; | |
215 | static const ]b4_int_type_for([b4_defgoto])[ defgoto_[]; | |
216 | static const ]b4_int_type_for([b4_table])[ table_[]; | |
217 | static const ]b4_int_type_for([b4_table])[ table_ninf_; | |
218 | static const ]b4_int_type_for([b4_check])[ check_[]; | |
219 | static const ]b4_int_type_for([b4_r1])[ r1_[]; | |
220 | static const ]b4_int_type_for([b4_r2])[ r2_[]; | |
69e2658b RA |
221 | |
222 | #if YYDEBUG || YYERROR_VERBOSE | |
c5e3e510 | 223 | static const char* const name_[]; |
69e2658b | 224 | #endif |
2b548aa6 RA |
225 | |
226 | /* More tables, for debugging. */ | |
69e2658b | 227 | #if YYDEBUG |
c5e3e510 AD |
228 | static const RhsNumberType rhs_[]; |
229 | static const ]b4_int_type_for([b4_prhs])[ prhs_[]; | |
230 | static const ]b4_int_type_for([b4_rline])[ rline_[]; | |
231 | static const ]b4_int_type_for([b4_stos])[ stos_[]; | |
232 | static const ]b4_int_type_for([b4_toknum])[ token_number_[]; | |
69e2658b | 233 | #endif |
2b548aa6 RA |
234 | |
235 | /* Even more tables. */ | |
680e8701 | 236 | static inline TokenNumberType translate_ (int token); |
2b548aa6 | 237 | |
762a801e | 238 | /* Constants. */ |
50997c6e | 239 | static const int eof_; |
39912f52 | 240 | /* LAST_ -- Last index in TABLE_. */ |
69e2658b | 241 | static const int last_; |
69e2658b | 242 | static const int nnts_; |
50997c6e | 243 | static const int empty_; |
69e2658b | 244 | static const int final_; |
762a801e RA |
245 | static const int terror_; |
246 | static const int errcode_; | |
50997c6e | 247 | static const int ntokens_; |
007a50a4 AD |
248 | static const unsigned user_token_number_max_; |
249 | static const TokenNumberType undef_token_; | |
2b548aa6 RA |
250 | |
251 | /* State. */ | |
69e2658b RA |
252 | int n_; |
253 | int len_; | |
69e2658b | 254 | int state_; |
4bb2bc3f | 255 | |
717be197 AD |
256 | /* Debugging. */ |
257 | int debug_; | |
258 | std::ostream &cdebug_; | |
259 | ||
69e2658b RA |
260 | /* Lookahead and lookahead in internal form. */ |
261 | int looka_; | |
262 | int ilooka_; | |
4bb2bc3f RA |
263 | |
264 | /* Message. */ | |
265 | std::string message; | |
266 | ||
374f5a14 | 267 | /* Semantic value and location of lookahead token. */ |
2b548aa6 RA |
268 | SemanticType value; |
269 | LocationType location; | |
8d69a1a3 | 270 | |
6ad762a8 | 271 | /* @@$ and $$. */ |
374f5a14 RA |
272 | SemanticType yyval; |
273 | LocationType yyloc; | |
274 | ||
8d69a1a3 RA |
275 | /* Initial location. */ |
276 | LocationType initlocation_; | |
2b548aa6 RA |
277 | }; |
278 | } | |
279 | ||
c5e3e510 | 280 | #endif /* ! defined PARSER_HEADER_H */] |
b61c6978 | 281 | ])dnl |
6ad762a8 | 282 | @output @output_parser_name@ |
fb8135fa | 283 | b4_copyright([C++ Skeleton parser for LALR(1) parsing with Bison], |
b61c6978 | 284 | [2002, 2003]) |
98254360 | 285 | |
b61c6978 | 286 | m4_if(b4_defines_flag, 0, [], [#include @output_header_name@])[ |
50997c6e | 287 | |
2b548aa6 | 288 | /* Enable debugging if requested. */ |
50997c6e | 289 | #if YYDEBUG |
717be197 | 290 | # define YYCDEBUG if (debug_) cdebug_ |
2b548aa6 | 291 | #else /* !YYDEBUG */ |
717be197 | 292 | # define YYCDEBUG if (0) cdebug_ |
2b548aa6 RA |
293 | #endif /* !YYDEBUG */ |
294 | ||
60a777aa AD |
295 | #define YYACCEPT goto yyacceptlab |
296 | #define YYABORT goto yyabortlab | |
297 | #define YYERROR goto yyerrlab1 | |
298 | ||
299 | ||
2b548aa6 | 300 | int |
c5e3e510 | 301 | yy::]b4_parser_class_name[::parse () |
2b548aa6 | 302 | { |
4bb2bc3f RA |
303 | int nerrs = 0; |
304 | int errstatus = 0; | |
305 | ||
3ae831b4 AD |
306 | /* Initialize the stacks. The initial state will be pushed in |
307 | yynewstate, since the latter expects the semantical and the | |
308 | location values to have been already stored, initialize these | |
309 | stacks with a primary value. */ | |
69e2658b RA |
310 | state_stack_ = StateStack (0); |
311 | semantic_stack_ = SemanticStack (1); | |
312 | location_stack_ = LocationStack (1); | |
2b548aa6 | 313 | |
2b548aa6 | 314 | /* Start. */ |
69e2658b RA |
315 | state_ = 0; |
316 | looka_ = empty_; | |
8d69a1a3 RA |
317 | #if YYLSP_NEEDED |
318 | location = initlocation_; | |
319 | #endif | |
717be197 | 320 | YYCDEBUG << "Starting parse" << std::endl; |
2b548aa6 RA |
321 | |
322 | /* New state. */ | |
323 | yynewstate: | |
69e2658b | 324 | state_stack_.push (state_); |
717be197 | 325 | YYCDEBUG << "Entering state " << state_ << std::endl; |
50997c6e | 326 | goto yybackup; |
2b548aa6 RA |
327 | |
328 | /* Backup. */ | |
329 | yybackup: | |
330 | ||
331 | /* Try to take a decision without lookahead. */ | |
c5e3e510 | 332 | n_ = pact_[state_]; |
12b0043a | 333 | if (n_ == pact_ninf_) |
2b548aa6 RA |
334 | goto yydefault; |
335 | ||
336 | /* Read a lookahead token. */ | |
69e2658b | 337 | if (looka_ == empty_) |
2b548aa6 | 338 | { |
717be197 | 339 | YYCDEBUG << "Reading a token: "; |
69e2658b | 340 | lex_ (); |
2b548aa6 RA |
341 | } |
342 | ||
343 | /* Convert token to internal form. */ | |
69e2658b | 344 | if (looka_ <= 0) |
2b548aa6 | 345 | { |
69e2658b RA |
346 | looka_ = eof_; |
347 | ilooka_ = 0; | |
717be197 | 348 | YYCDEBUG << "Now at end of input." << std::endl; |
2b548aa6 RA |
349 | } |
350 | else | |
351 | { | |
69e2658b | 352 | ilooka_ = translate_ (looka_); |
50997c6e RA |
353 | #if YYDEBUG |
354 | if (debug_) | |
355 | { | |
717be197 | 356 | YYCDEBUG << "Next token is " << looka_ |
c5e3e510 | 357 | << " (" << name_[ilooka_]; |
4aacc3a7 | 358 | print_ (); |
717be197 | 359 | YYCDEBUG << ')' << std::endl; |
50997c6e | 360 | } |
2b548aa6 RA |
361 | #endif |
362 | } | |
363 | ||
69e2658b | 364 | n_ += ilooka_; |
c5e3e510 | 365 | if (n_ < 0 || last_ < n_ || check_[n_] != ilooka_) |
2b548aa6 RA |
366 | goto yydefault; |
367 | ||
368 | /* Reduce or error. */ | |
c5e3e510 | 369 | n_ = table_[n_]; |
69e2658b | 370 | if (n_ < 0) |
2b548aa6 | 371 | { |
12b0043a | 372 | if (n_ == table_ninf_) |
2b548aa6 RA |
373 | goto yyerrlab; |
374 | else | |
375 | { | |
69e2658b | 376 | n_ = -n_; |
2b548aa6 RA |
377 | goto yyreduce; |
378 | } | |
379 | } | |
69e2658b | 380 | else if (n_ == 0) |
2b548aa6 | 381 | goto yyerrlab; |
a75c057f | 382 | |
2b548aa6 | 383 | /* Accept? */ |
69e2658b | 384 | if (n_ == final_) |
2b548aa6 RA |
385 | goto yyacceptlab; |
386 | ||
387 | /* Shift the lookahead token. */ | |
fc049e9c | 388 | #if YYDEBUG |
717be197 | 389 | YYCDEBUG << "Shifting token " << looka_ |
fc049e9c AD |
390 | << " (" << name_[ilooka_] << "), "; |
391 | #endif | |
2b548aa6 RA |
392 | |
393 | /* Discard the token being shifted unless it is eof. */ | |
69e2658b RA |
394 | if (looka_ != eof_) |
395 | looka_ = empty_; | |
2b548aa6 | 396 | |
69e2658b RA |
397 | semantic_stack_.push (value); |
398 | location_stack_.push (location); | |
8d69a1a3 RA |
399 | |
400 | /* Count tokens shifted since error; after three, turn off error | |
401 | status. */ | |
402 | if (errstatus) | |
403 | --errstatus; | |
404 | ||
69e2658b | 405 | state_ = n_; |
2b548aa6 RA |
406 | goto yynewstate; |
407 | ||
408 | /* Default action. */ | |
409 | yydefault: | |
c5e3e510 | 410 | n_ = defact_[state_]; |
69e2658b | 411 | if (n_ == 0) |
2b548aa6 | 412 | goto yyerrlab; |
50997c6e | 413 | goto yyreduce; |
2b548aa6 RA |
414 | |
415 | /* Reduce. */ | |
416 | yyreduce: | |
c5e3e510 | 417 | len_ = r2_[n_]; |
69e2658b | 418 | if (len_) |
50997c6e | 419 | { |
c5e3e510 AD |
420 | yyval = semantic_stack_[len_ - 1]; |
421 | yyloc = location_stack_[len_ - 1]; | |
50997c6e RA |
422 | } |
423 | else | |
69e2658b | 424 | { |
c5e3e510 AD |
425 | yyval = semantic_stack_[0]; |
426 | yyloc = location_stack_[0]; | |
50997c6e | 427 | } |
2b548aa6 | 428 | |
50997c6e RA |
429 | #if YYDEBUG |
430 | if (debug_) | |
2b548aa6 | 431 | { |
0d1c3a04 AD |
432 | // Short files will use "unsigned char" for line numbers, |
433 | // in which case they will be output as character litterals | |
434 | // by "<<". | |
717be197 | 435 | YYCDEBUG << "Reducing via rule " << n_ - 1 |
0d1c3a04 | 436 | << " (line " << static_cast <unsigned> (rline_[n_]) << "), "; |
c5e3e510 AD |
437 | for (]b4_int_type_for([b4_prhs])[ i = prhs_[n_]; |
438 | 0 <= rhs_[i]; ++i) | |
439 | YYCDEBUG << name_[rhs_[i]] << ' '; | |
440 | YYCDEBUG << "-> " << name_[r1_[n_]] << std::endl; | |
2b548aa6 RA |
441 | } |
442 | #endif | |
a75c057f | 443 | |
374f5a14 RA |
444 | if (len_) |
445 | { | |
446 | Slice< LocationType, LocationStack > slice (location_stack_, len_); | |
447 | YYLLOC_DEFAULT (yyloc, slice, len_); | |
448 | } | |
449 | ||
45119f04 RA |
450 | switch (n_) |
451 | { | |
c5e3e510 | 452 | ]b4_actions[ |
45119f04 | 453 | } |
a75c057f | 454 | |
996b1c7e | 455 | ]/* Line __line__ of lalr1.cc. */ |
c5e3e510 | 456 | b4_syncline([@oline@], [@ofile@])[ |
06446ccf | 457 | |
69e2658b RA |
458 | state_stack_.pop (len_); |
459 | semantic_stack_.pop (len_); | |
460 | location_stack_.pop (len_); | |
2b548aa6 | 461 | |
50997c6e RA |
462 | #if YYDEBUG |
463 | if (debug_) | |
2b548aa6 | 464 | { |
717be197 | 465 | YYCDEBUG << "state stack now"; |
a75c057f | 466 | for (StateStack::ConstIterator i = state_stack_.begin (); |
69e2658b | 467 | i != state_stack_.end (); ++i) |
717be197 AD |
468 | YYCDEBUG << ' ' << *i; |
469 | YYCDEBUG << std::endl; | |
2b548aa6 RA |
470 | } |
471 | #endif | |
a75c057f | 472 | |
374f5a14 RA |
473 | semantic_stack_.push (yyval); |
474 | location_stack_.push (yyloc); | |
2b548aa6 RA |
475 | |
476 | /* Shift the result of the reduction. */ | |
c5e3e510 AD |
477 | n_ = r1_[n_]; |
478 | state_ = pgoto_[n_ - ntokens_] + state_stack_[0]; | |
479 | if (0 <= state_ && state_ <= last_ && check_[state_] == state_stack_[0]) | |
480 | state_ = table_[state_]; | |
2b548aa6 | 481 | else |
c5e3e510 | 482 | state_ = defgoto_[n_ - ntokens_]; |
2b548aa6 RA |
483 | goto yynewstate; |
484 | ||
485 | /* Report and recover from errors. This is very incomplete. */ | |
486 | yyerrlab: | |
4bb2bc3f RA |
487 | /* If not already recovering from an error, report this error. */ |
488 | if (!errstatus) | |
489 | { | |
490 | ++nerrs; | |
a75c057f | 491 | |
69e2658b | 492 | #if YYERROR_VERBOSE |
c5e3e510 | 493 | n_ = pact_[state_]; |
12b0043a | 494 | if (pact_ninf_ < n_ && n_ < last_) |
4bb2bc3f | 495 | { |
6e649e65 | 496 | message = "syntax error, unexpected "; |
c5e3e510 | 497 | message += name_[ilooka_]; |
4bb2bc3f RA |
498 | { |
499 | int 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 RA |
502 | ++count; |
503 | if (count < 5) | |
504 | { | |
505 | count = 0; | |
69e2658b | 506 | for (int x = (n_ < 0 ? -n_ : 0); x < ntokens_ + nnts_; ++x) |
c5e3e510 | 507 | if (check_[x + n_] == x && x != terror_) |
4bb2bc3f | 508 | { |
a75c057f | 509 | message += (!count++) ? ", expecting " : " or "; |
c5e3e510 | 510 | message += name_[x]; |
4bb2bc3f RA |
511 | } |
512 | } | |
513 | } | |
514 | } | |
515 | else | |
69e2658b | 516 | #endif |
6e649e65 | 517 | message = "syntax error"; |
8d69a1a3 | 518 | error_ (); |
4bb2bc3f | 519 | } |
762a801e | 520 | goto yyerrlab1; |
a75c057f | 521 | |
60a777aa AD |
522 | |
523 | /*----------------------------------------------------. | |
524 | | yyerrlab1 -- error raised explicitly by an action. | | |
525 | `----------------------------------------------------*/ | |
762a801e RA |
526 | yyerrlab1: |
527 | if (errstatus == 3) | |
528 | { | |
529 | /* If just tried and failed to reuse lookahead token after an | |
530 | error, discard it. */ | |
531 | ||
532 | /* Return failure if at end of input. */ | |
69e2658b | 533 | if (looka_ == eof_) |
762a801e | 534 | goto yyabortlab; |
7548fed2 | 535 | #if YYDEBUG |
717be197 | 536 | YYCDEBUG << "Discarding token " << looka_ |
7548fed2 AD |
537 | << " (" << name_[ilooka_] << ")." << std::endl; |
538 | #endif | |
69e2658b | 539 | looka_ = empty_; |
762a801e RA |
540 | } |
541 | ||
542 | /* Else will try to reuse lookahead token after shifting the error | |
543 | token. */ | |
544 | ||
545 | errstatus = 3; | |
762a801e | 546 | |
769b430f AD |
547 | for (;;) |
548 | { | |
c5e3e510 | 549 | n_ = pact_[state_]; |
12b0043a | 550 | if (n_ != pact_ninf_) |
769b430f AD |
551 | { |
552 | n_ += terror_; | |
c5e3e510 | 553 | if (0 <= n_ && n_ <= last_ && check_[n_] == terror_) |
769b430f | 554 | { |
c5e3e510 | 555 | n_ = table_[n_]; |
769b430f AD |
556 | if (0 < n_) |
557 | break; | |
558 | } | |
559 | } | |
560 | ||
561 | /* Pop the current state because it cannot handle the error token. */ | |
3ae831b4 | 562 | if (state_stack_.height () == 1) |
769b430f | 563 | goto yyabortlab; |
762a801e RA |
564 | |
565 | #if YYDEBUG | |
769b430f AD |
566 | if (debug_) |
567 | { | |
c5e3e510 | 568 | if (stos_[state_] < ntokens_) |
769b430f | 569 | { |
717be197 | 570 | YYCDEBUG << "Error: popping token " |
c5e3e510 AD |
571 | << token_number_[stos_[state_]] |
572 | << " (" << name_[stos_[state_]]; | |
769b430f | 573 | # ifdef YYPRINT |
c5e3e510 | 574 | YYPRINT (stderr, token_number_[stos_[state_]], |
769b430f AD |
575 | semantic_stack_.top ()); |
576 | # endif | |
717be197 | 577 | YYCDEBUG << ')' << std::endl; |
769b430f AD |
578 | } |
579 | else | |
580 | { | |
717be197 | 581 | YYCDEBUG << "Error: popping nonterminal (" |
c5e3e510 | 582 | << name_[stos_[state_]] << ')' << std::endl; |
769b430f AD |
583 | } |
584 | } | |
762a801e RA |
585 | #endif |
586 | ||
c5e3e510 | 587 | state_ = (state_stack_.pop (), state_stack_[0]); |
769b430f AD |
588 | semantic_stack_.pop (); |
589 | location_stack_.pop ();; | |
762a801e | 590 | |
769b430f AD |
591 | #if YYDEBUG |
592 | if (debug_) | |
593 | { | |
717be197 | 594 | YYCDEBUG << "Error: state stack now"; |
769b430f AD |
595 | for (StateStack::ConstIterator i = state_stack_.begin (); |
596 | i != state_stack_.end (); ++i) | |
717be197 AD |
597 | YYCDEBUG << ' ' << *i; |
598 | YYCDEBUG << std::endl; | |
769b430f AD |
599 | } |
600 | #endif | |
762a801e | 601 | } |
762a801e | 602 | |
69e2658b | 603 | if (n_ == final_) |
762a801e RA |
604 | goto yyacceptlab; |
605 | ||
717be197 | 606 | YYCDEBUG << "Shifting error token, "; |
762a801e | 607 | |
69e2658b RA |
608 | semantic_stack_.push (value); |
609 | location_stack_.push (location); | |
762a801e | 610 | |
69e2658b | 611 | state_ = n_; |
762a801e RA |
612 | goto yynewstate; |
613 | ||
2b548aa6 RA |
614 | /* Accept. */ |
615 | yyacceptlab: | |
616 | return 0; | |
762a801e RA |
617 | |
618 | /* Abort. */ | |
619 | yyabortlab: | |
620 | return 1; | |
2b548aa6 RA |
621 | } |
622 | ||
69e2658b | 623 | void |
c5e3e510 | 624 | yy::]b4_parser_class_name[::lex_ () |
69e2658b RA |
625 | { |
626 | #if YYLSP_NEEDED | |
627 | looka_ = yylex (&value, &location); | |
628 | #else | |
629 | looka_ = yylex (&value); | |
630 | #endif | |
631 | } | |
632 | ||
c5e3e510 | 633 | /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing |
2b548aa6 | 634 | STATE-NUM. */ |
c5e3e510 AD |
635 | const ]b4_int_type_for([b4_pact]) yy::b4_parser_class_name::pact_ninf_ = b4_pact_ninf[; |
636 | const ]b4_int_type_for([b4_pact])[ | |
637 | yy::]b4_parser_class_name[::pact_[] = | |
2b548aa6 | 638 | { |
c5e3e510 | 639 | ]b4_pact[ |
2b548aa6 RA |
640 | }; |
641 | ||
c5e3e510 | 642 | /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE |
2b548aa6 RA |
643 | doesn't specify something else to do. Zero means the default is an |
644 | error. */ | |
c5e3e510 AD |
645 | const ]b4_int_type_for([b4_defact])[ |
646 | yy::]b4_parser_class_name[::defact_[] = | |
2b548aa6 | 647 | { |
c5e3e510 | 648 | ]b4_defact[ |
2b548aa6 RA |
649 | }; |
650 | ||
c5e3e510 AD |
651 | /* YYPGOTO[NTERM-NUM]. */ |
652 | const ]b4_int_type_for([b4_pgoto])[ | |
653 | yy::]b4_parser_class_name[::pgoto_[] = | |
2b548aa6 | 654 | { |
c5e3e510 | 655 | ]b4_pgoto[ |
2b548aa6 RA |
656 | }; |
657 | ||
c5e3e510 AD |
658 | /* YYDEFGOTO[NTERM-NUM]. */ |
659 | const ]b4_int_type_for([b4_defgoto])[ | |
660 | yy::]b4_parser_class_name[::defgoto_[] = | |
2b548aa6 | 661 | { |
c5e3e510 | 662 | ]b4_defgoto[ |
2b548aa6 RA |
663 | }; |
664 | ||
c5e3e510 | 665 | /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If |
2b548aa6 RA |
666 | positive, shift that token. If negative, reduce the rule which |
667 | number is the opposite. If zero, do what YYDEFACT says. */ | |
c5e3e510 AD |
668 | const ]b4_int_type_for([b4_table]) yy::b4_parser_class_name::table_ninf_ = b4_table_ninf[; |
669 | const ]b4_int_type_for([b4_table])[ | |
670 | yy::]b4_parser_class_name[::table_[] = | |
2b548aa6 | 671 | { |
c5e3e510 | 672 | ]b4_table[ |
2b548aa6 RA |
673 | }; |
674 | ||
675 | /* YYCHECK. */ | |
c5e3e510 AD |
676 | const ]b4_int_type_for([b4_check])[ |
677 | yy::]b4_parser_class_name[::check_[] = | |
2b548aa6 | 678 | { |
c5e3e510 | 679 | ]b4_check[ |
2b548aa6 RA |
680 | }; |
681 | ||
769b430f | 682 | #if YYDEBUG |
c5e3e510 | 683 | /* STOS_[STATE-NUM] -- The (internal number of the) accessing |
769b430f | 684 | symbol of state STATE-NUM. */ |
c5e3e510 AD |
685 | const ]b4_int_type_for([b4_stos])[ |
686 | yy::]b4_parser_class_name[::stos_[] = | |
769b430f | 687 | { |
c5e3e510 | 688 | ]b4_stos[ |
769b430f AD |
689 | }; |
690 | ||
c5e3e510 | 691 | /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal token number corresponding |
769b430f | 692 | to YYLEX-NUM. */ |
c5e3e510 AD |
693 | const ]b4_int_type_for([b4_toknum])[ |
694 | yy::]b4_parser_class_name[::token_number_[] = | |
769b430f | 695 | { |
c5e3e510 | 696 | ]b4_toknum[ |
769b430f AD |
697 | }; |
698 | #endif | |
699 | ||
c5e3e510 AD |
700 | /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ |
701 | const ]b4_int_type_for([b4_r1])[ | |
702 | yy::]b4_parser_class_name[::r1_[] = | |
2b548aa6 | 703 | { |
c5e3e510 | 704 | ]b4_r1[ |
2b548aa6 RA |
705 | }; |
706 | ||
c5e3e510 AD |
707 | /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ |
708 | const ]b4_int_type_for([b4_r2])[ | |
709 | yy::]b4_parser_class_name[::r2_[] = | |
2b548aa6 | 710 | { |
c5e3e510 | 711 | ]b4_r2[ |
2b548aa6 RA |
712 | }; |
713 | ||
69e2658b | 714 | #if YYDEBUG || YYERROR_VERBOSE |
c5e3e510 | 715 | /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. |
2b548aa6 RA |
716 | First, the terminals, then, starting at YYNTOKENS, nonterminals. */ |
717 | const char* | |
c5e3e510 | 718 | const yy::]b4_parser_class_name[::name_[] = |
2b548aa6 | 719 | { |
c5e3e510 | 720 | ]b4_tname[ |
2b548aa6 | 721 | }; |
69e2658b | 722 | #endif |
2b548aa6 | 723 | |
69e2658b | 724 | #if YYDEBUG |
2b548aa6 | 725 | /* YYRHS -- A `-1'-separated list of the rules' RHS. */ |
c5e3e510 AD |
726 | const yy::]b4_parser_class_name[::RhsNumberType |
727 | yy::]b4_parser_class_name[::rhs_[] = | |
2b548aa6 | 728 | { |
c5e3e510 | 729 | ]b4_rhs[ |
2b548aa6 RA |
730 | }; |
731 | ||
c5e3e510 | 732 | /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in |
2b548aa6 | 733 | YYRHS. */ |
c5e3e510 AD |
734 | const ]b4_int_type_for([b4_prhs])[ |
735 | yy::]b4_parser_class_name[::prhs_[] = | |
2b548aa6 | 736 | { |
c5e3e510 | 737 | ]b4_prhs[ |
2b548aa6 RA |
738 | }; |
739 | ||
c5e3e510 AD |
740 | /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ |
741 | const ]b4_int_type_for([b4_rline])[ | |
742 | yy::]b4_parser_class_name[::rline_[] = | |
69e2658b | 743 | { |
c5e3e510 | 744 | ]b4_rline[ |
69e2658b RA |
745 | }; |
746 | #endif | |
747 | ||
2b548aa6 | 748 | /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ |
c5e3e510 AD |
749 | yy::]b4_parser_class_name[::TokenNumberType |
750 | yy::]b4_parser_class_name[::translate_ (int token) | |
2b548aa6 | 751 | { |
a75c057f | 752 | static |
680e8701 | 753 | const TokenNumberType |
c5e3e510 | 754 | translate_[] = |
2b548aa6 | 755 | { |
c5e3e510 | 756 | ]b4_translate[ |
2b548aa6 | 757 | }; |
007a50a4 | 758 | if ((unsigned) token <= user_token_number_max_) |
c5e3e510 | 759 | return translate_[token]; |
007a50a4 AD |
760 | else |
761 | return undef_token_; | |
2b548aa6 RA |
762 | } |
763 | ||
c5e3e510 AD |
764 | const int yy::]b4_parser_class_name[::eof_ = 0; |
765 | const int yy::]b4_parser_class_name[::last_ = ]b4_last[; | |
766 | const int yy::]b4_parser_class_name[::nnts_ = ]b4_nterms_number[; | |
767 | const int yy::]b4_parser_class_name[::empty_ = -2; | |
768 | const int yy::]b4_parser_class_name[::final_ = ]b4_final_state_number[; | |
769 | const int yy::]b4_parser_class_name[::terror_ = 1; | |
770 | const int yy::]b4_parser_class_name[::errcode_ = 256; | |
771 | const int yy::]b4_parser_class_name[::ntokens_ = ]b4_tokens_number[; | |
66d30cd4 | 772 | |
c5e3e510 AD |
773 | const unsigned yy::]b4_parser_class_name[::user_token_number_max_ = ]b4_user_token_number_max[; |
774 | const yy::]b4_parser_class_name[::TokenNumberType yy::]b4_parser_class_name[::undef_token_ = ]b4_undef_token_number[; | |
2b548aa6 | 775 | |
c5e3e510 | 776 | ]b4_epilogue |
21846f69 | 777 | dnl |
6ad762a8 | 778 | @output stack.hh |
7548fed2 | 779 | b4_copyright([Stack handling for Bison C++ parsers], [2002, 2003])[ |
98254360 | 780 | |
2b548aa6 RA |
781 | #ifndef BISON_STACK_HH |
782 | # define BISON_STACK_HH | |
783 | ||
45119f04 | 784 | #include <deque> |
2b548aa6 RA |
785 | |
786 | namespace yy | |
787 | { | |
45119f04 | 788 | template < class T, class S = std::deque< T > > |
2b548aa6 RA |
789 | class Stack |
790 | { | |
791 | public: | |
792 | ||
793 | typedef typename S::iterator Iterator; | |
794 | typedef typename S::const_iterator ConstIterator; | |
795 | ||
796 | Stack () : seq_ () | |
797 | { | |
798 | } | |
799 | ||
800 | Stack (unsigned n) : seq_ (n) | |
801 | { | |
802 | } | |
803 | ||
804 | inline | |
805 | T& | |
c5e3e510 | 806 | operator [] (unsigned index) |
2b548aa6 | 807 | { |
c5e3e510 | 808 | return seq_[index]; |
2b548aa6 RA |
809 | } |
810 | ||
811 | inline | |
812 | const T& | |
c5e3e510 | 813 | operator [] (unsigned index) const |
2b548aa6 | 814 | { |
c5e3e510 | 815 | return seq_[index]; |
2b548aa6 RA |
816 | } |
817 | ||
818 | inline | |
819 | void | |
820 | push (const T& t) | |
821 | { | |
45119f04 | 822 | seq_.push_front (t); |
2b548aa6 RA |
823 | } |
824 | ||
825 | inline | |
826 | void | |
827 | pop (unsigned n = 1) | |
828 | { | |
829 | for (; n; --n) | |
45119f04 | 830 | seq_.pop_front (); |
2b548aa6 RA |
831 | } |
832 | ||
762a801e RA |
833 | inline |
834 | unsigned | |
835 | height () const | |
836 | { | |
837 | return seq_.size (); | |
838 | } | |
839 | ||
2b548aa6 RA |
840 | inline ConstIterator begin () const { return seq_.begin (); } |
841 | inline ConstIterator end () const { return seq_.end (); } | |
842 | ||
843 | private: | |
844 | ||
845 | S seq_; | |
846 | }; | |
374f5a14 RA |
847 | |
848 | template < class T, class S = Stack< T > > | |
849 | class Slice | |
850 | { | |
851 | public: | |
852 | ||
853 | Slice (const S& stack, | |
854 | unsigned range) : stack_ (stack), | |
855 | range_ (range) | |
856 | { | |
857 | } | |
858 | ||
859 | inline | |
860 | const T& | |
c5e3e510 | 861 | operator [] (unsigned index) const |
374f5a14 | 862 | { |
c5e3e510 | 863 | return stack_[range_ - index]; |
374f5a14 RA |
864 | } |
865 | ||
866 | private: | |
867 | ||
868 | const S& stack_; | |
869 | unsigned range_; | |
870 | }; | |
2b548aa6 RA |
871 | } |
872 | ||
c5e3e510 | 873 | #endif // not BISON_STACK_HH] |
21846f69 | 874 | dnl |
5d003116 AD |
875 | @output position.hh |
876 | b4_copyright([Position class for Bison C++ parsers], [2002, 2003])[ | |
98254360 | 877 | |
5d003116 AD |
878 | /** |
879 | ** \file position.hh | |
880 | ** Define the Location class. | |
881 | */ | |
882 | ||
883 | #ifndef BISON_POSITION_HH | |
884 | # define BISON_POSITION_HH | |
2b548aa6 | 885 | |
7548fed2 AD |
886 | # include <iostream> |
887 | # include <string> | |
888 | ||
2b548aa6 RA |
889 | namespace yy |
890 | { | |
5d003116 | 891 | /** \brief Abstract a Position. */ |
7548fed2 | 892 | class Position |
2b548aa6 | 893 | { |
7548fed2 | 894 | public: |
5d003116 AD |
895 | /** \brief Initial column number. */ |
896 | static const unsigned int initial_column = 0; | |
897 | /** \brief Initial line number. */ | |
898 | static const unsigned int initial_line = 1; | |
899 | ||
900 | /** \name Ctor & dtor. | |
901 | ** \{ */ | |
902 | public: | |
903 | /** \brief Construct a Position. */ | |
904 | Position () : | |
905 | filename (), | |
906 | line (initial_line), | |
907 | column (initial_column) | |
908 | { | |
909 | } | |
910 | /** \} */ | |
911 | ||
7548fed2 | 912 | |
5d003116 AD |
913 | /** \name Line and Column related manipulators |
914 | ** \{ */ | |
915 | public: | |
916 | /** \brief (line related) Advance to the LINES next lines. */ | |
917 | inline void lines (int lines = 1) | |
918 | { | |
919 | column = initial_column; | |
920 | line += lines; | |
921 | } | |
922 | ||
923 | /** \brief (column related) Advance to the COLUMNS next columns. */ | |
924 | inline void columns (int columns = 1) | |
925 | { | |
2cdc240e AD |
926 | if (int (initial_column) < columns + int (column)) |
927 | column += columns; | |
928 | else | |
929 | column = initial_column; | |
5d003116 AD |
930 | } |
931 | /** \} */ | |
932 | ||
933 | public: | |
934 | /** \brief File name to which this position refers. */ | |
7548fed2 | 935 | std::string filename; |
5d003116 AD |
936 | /** \brief Current line number. */ |
937 | unsigned int line; | |
938 | /** \brief Current column number. */ | |
939 | unsigned int column; | |
2b548aa6 RA |
940 | }; |
941 | ||
5d003116 AD |
942 | /** \brief Add and assign a Position. */ |
943 | inline const Position& | |
944 | operator+= (Position& res, const int width) | |
945 | { | |
946 | res.columns (width); | |
947 | return res; | |
948 | } | |
949 | ||
950 | /** \brief Add two Position objects. */ | |
951 | inline const Position | |
952 | operator+ (const Position& begin, const int width) | |
953 | { | |
954 | Position res = begin; | |
955 | return res += width; | |
956 | } | |
957 | ||
958 | /** \brief Add and assign a Position. */ | |
959 | inline const Position& | |
960 | operator-= (Position& res, const int width) | |
961 | { | |
962 | return res += -width; | |
963 | } | |
964 | ||
965 | /** \brief Add two Position objects. */ | |
966 | inline const Position | |
967 | operator- (const Position& begin, const int width) | |
968 | { | |
969 | return begin + -width; | |
970 | } | |
971 | ||
972 | /** \brief Intercept output stream redirection. | |
973 | ** \param ostr the destination output stream | |
974 | ** \param pos a reference to the Position to redirect | |
975 | */ | |
7548fed2 AD |
976 | inline std::ostream& |
977 | operator<< (std::ostream& ostr, const Position& pos) | |
978 | { | |
979 | if (pos.filename != "") | |
980 | ostr << pos.filename << ':'; | |
5d003116 | 981 | return ostr << pos.line << '.' << pos.column; |
7548fed2 AD |
982 | } |
983 | ||
5d003116 AD |
984 | } |
985 | #endif // not BISON_POSITION_HH] | |
986 | @output location.hh | |
987 | b4_copyright([Location class for Bison C++ parsers], [2002, 2003])[ | |
7548fed2 | 988 | |
5d003116 AD |
989 | /** |
990 | ** \file location.hh | |
991 | ** Define the Location class. | |
992 | */ | |
7548fed2 | 993 | |
5d003116 AD |
994 | #ifndef BISON_LOCATION_HH |
995 | # define BISON_LOCATION_HH | |
996 | ||
997 | # include <iostream> | |
998 | # include <string> | |
999 | # include "position.hh" | |
1000 | ||
1001 | namespace yy | |
1002 | { | |
1003 | ||
1004 | /** \brief Abstract a Location. */ | |
7548fed2 | 1005 | class Location |
2b548aa6 | 1006 | { |
5d003116 AD |
1007 | /** \name Ctor & dtor. |
1008 | ** \{ */ | |
7548fed2 | 1009 | public: |
5d003116 AD |
1010 | /** \brief Construct a Location. */ |
1011 | Location (void) : | |
1012 | begin (), | |
1013 | end () | |
1014 | { | |
1015 | } | |
1016 | /** \} */ | |
1017 | ||
1018 | ||
1019 | /** \name Line and Column related manipulators | |
1020 | ** \{ */ | |
1021 | public: | |
1022 | /** \brief Reset initial location to final location. */ | |
1023 | inline void step (void) | |
1024 | { | |
1025 | begin = end; | |
1026 | } | |
1027 | ||
1028 | /** \brief Extend the current location to the COLUMNS next columns. */ | |
1029 | inline void columns (unsigned columns = 1) | |
1030 | { | |
1031 | end += columns; | |
1032 | } | |
1033 | ||
1034 | /** \brief Extend the current location to the LINES next lines. */ | |
1035 | inline void lines (unsigned lines = 1) | |
1036 | { | |
1037 | end.lines (lines); | |
1038 | } | |
1039 | /** \} */ | |
1040 | ||
1041 | ||
1042 | public: | |
1043 | /** \brief Beginning of the located region. */ | |
7548fed2 | 1044 | Position begin; |
5d003116 | 1045 | /** \brief End of the located region. */ |
7548fed2 | 1046 | Position end; |
2b548aa6 | 1047 | }; |
7548fed2 | 1048 | |
5d003116 AD |
1049 | /** \brief Join two Location objects to create a Location. */ |
1050 | inline const Location operator+ (const Location& begin, const Location& end) | |
1051 | { | |
1052 | Location res = begin; | |
1053 | res.end = end.end; | |
1054 | return res; | |
1055 | } | |
1056 | ||
1057 | /** \brief Add two Location objects */ | |
1058 | inline const Location operator+ (const Location& begin, unsigned width) | |
1059 | { | |
1060 | Location res = begin; | |
1061 | res.columns (width); | |
1062 | return res; | |
1063 | } | |
7548fed2 | 1064 | |
5d003116 AD |
1065 | /** \brief Add and assign a Location */ |
1066 | inline Location &operator+= (Location& res, unsigned width) | |
1067 | { | |
1068 | res.columns (width); | |
1069 | return res; | |
1070 | } | |
1071 | ||
1072 | /** \brief Intercept output stream redirection. | |
1073 | ** \param ostr the destination output stream | |
2cdc240e | 1074 | ** \param loc a reference to the Location to redirect |
5d003116 | 1075 | ** |
2cdc240e | 1076 | ** Avoid duplicate information. |
5d003116 | 1077 | */ |
2cdc240e | 1078 | inline std::ostream& operator<< (std::ostream& ostr, const Location& loc) |
7548fed2 | 1079 | { |
2cdc240e AD |
1080 | Position last = loc.end - 1; |
1081 | ostr << loc.begin; | |
1082 | if (loc.begin.filename != last.filename) | |
1083 | ostr << '-' << last; | |
1084 | else if (loc.begin.line != last.line) | |
1085 | ostr << '-' << last.line << '.' << last.column; | |
1086 | else if (loc.begin.column != last.column) | |
1087 | ostr << '-' << last.column; | |
7548fed2 AD |
1088 | return ostr; |
1089 | } | |
1090 | ||
2b548aa6 RA |
1091 | } |
1092 | ||
c5e3e510 | 1093 | #endif // not BISON_LOCATION_HH] |