2 # C++ skeleton for Bison
3 # Copyright (C) 2002, 2003 Free Software Foundation, Inc.
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.
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.
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
20 ## ---------------- ##
22 ## ---------------- ##
24 # Default Parser class name.
25 m4_define_default([b4_parser_class_name
], [Parser
])
29 ## ----------------- ##
30 ## Semantic Values. ##
31 ## ----------------- ##
34 # b4_lhs_value([TYPE])
35 # --------------------
36 # Expansion of $<TYPE>$.
37 m4_define([b4_lhs_value
],
38 [yyval
[]m4_ifval([$
1], [.$
1])])
41 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
42 # --------------------------------------
43 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
45 m4_define([b4_rhs_value
],
46 [semantic_stack_@
{m4_eval([$
1 - $
2])@
}m4_ifval([$
3], [.$
3])])
48 m4_define_default([b4_location_type
], [Location
])
53 m4_define([b4_lhs_location
],
57 # b4_rhs_location(RULE-LENGTH, NUM)
58 # ---------------------------------
59 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
61 m4_define([b4_rhs_location
],
62 [location_stack_@
{m4_eval([$
1 - $
2])@
}])
65 m4_define([b4_inherit
],
77 m4_define([b4_constructor
],
86 # Constructor's extra arguments.
87 m4_define([b4_parse_param_decl],
88 [m4_ifset([b4_parse_param], [, b4_c_ansi_formals(b4_parse_param)])])
92 # constructor's extra initialisations.
93 m4_define([b4_parse_param_cons
],
94 [m4_ifset([b4_parse_param
],
96 b4_cc_constructor_calls(b4_parse_param
)])])
97 m4_define([b4_cc_constructor_calls
],
98 [m4_map_sep([b4_cc_constructor_call
], [,
100 m4_define([b4_cc_constructor_call
],
103 # b4_parse_param_vars
104 # -------------------
105 # Extra instance variables.
106 m4_define([b4_parse_param_vars
],
107 [m4_ifset([b4_parse_param
],
109 /* User arguments. */
110 b4_cc_var_decls(b4_parse_param
)])])
111 m4_define([b4_cc_var_decls
],
112 [m4_map_sep([b4_cc_var_decl
], [
114 m4_define([b4_cc_var_decl
],
117 # We do want M4 expansion after # for CPP macros.
120 m4_if(b4_defines_flag
, 0, [],
121 [@output @output_header_name@
122 b4_copyright([C
++ Skeleton parser
for LALR(1) parsing with Bison
],
124 /* FIXME: This is wrong, we want computed header guards.
125 I don't know why the macros are missing now. :( */
126 #ifndef PARSER_HEADER_H
127 # define PARSER_HEADER_H
130 #include "location.hh"
135 /* Using locations. */
136 #define YYLSP_NEEDED ]b4_locations_flag[
138 ]b4_token_defines(b4_tokens
)[
140 /* Copy the first part of user declarations. */
143 ]/* Line __line__ of lalr1.cc. */
144 b4_syncline([@oline@
], [@ofile@
])[
146 /* Enabling traces. */
148 # define YYDEBUG ]b4_debug[
151 /* Enabling verbose error message. */
152 #ifndef YYERROR_VERBOSE
153 # define YYERROR_VERBOSE ]b4_error_verbose[
157 ]m4_ifdef([b4_stype
],
158 [b4_syncline([b4_stype_line
], [b4_filename
])
159 typedef union b4_stype yystype
;
160 /* Line __line__ of lalr1.cc. */
161 b4_syncline([@oline@
], [@ofile@
])],
162 [typedef int yystype
;])[
163 # define YYSTYPE yystype
166 /* Copy the second part of user declarations. */
169 ]/* Line __line__ of lalr1.cc. */
170 b4_syncline([@oline@
], [@ofile@
])[
171 #ifndef YYLLOC_DEFAULT
172 # define YYLLOC_DEFAULT(Current, Rhs, N) \
173 ((Current).end = Rhs[N].end)
178 class ]b4_parser_class_name
[;
180 template < typename P
>
186 struct Traits
< ]b4_parser_class_name
[ >
188 typedef ]b4_int_type_for([b4_translate
])[ TokenNumberType
;
189 typedef ]b4_int_type_for([b4_rhs
])[ RhsNumberType
;
190 typedef int StateType
;
191 typedef yystype SemanticType
;
192 typedef ]b4_location_type
[ LocationType
;
198 class ]b4_parser_class_name b4_inherit
[
202 typedef Traits
< ]b4_parser_class_name
[ >::TokenNumberType TokenNumberType
;
203 typedef Traits
< ]b4_parser_class_name
[ >::RhsNumberType RhsNumberType
;
204 typedef Traits
< ]b4_parser_class_name
[ >::StateType StateType
;
205 typedef Traits
< ]b4_parser_class_name
[ >::SemanticType SemanticType
;
206 typedef Traits
< ]b4_parser_class_name
[ >::LocationType LocationType
;
208 typedef Stack
< StateType
> StateStack
;
209 typedef Stack
< SemanticType
> SemanticStack
;
210 typedef Stack
< LocationType
> LocationStack
;
213 ]b4_parser_class_name
[ (bool debug
,
214 LocationType initlocation
][]b4_param
[]b4_parse_param_decl
[) :
215 ]b4_constructor
[][debug_ (debug
),
217 initlocation_ (initlocation
)]b4_parse_param_cons
[
219 ]b4_parser_class_name
[ (bool debug
][]b4_param
[]b4_parse_param_decl
[) :
220 ]b4_constructor
[][debug_ (debug
),
221 cdebug_ (std::cerr
)]b4_parse_param_cons
[
226 virtual ~]b4_parser_class_name
[ ()
230 virtual int parse ();
234 virtual void lex_ ();
235 virtual void error_ ();
236 virtual void print_ ();
237 virtual void report_syntax_error_ ();
240 StateStack state_stack_
;
241 SemanticStack semantic_stack_
;
242 LocationStack location_stack_
;
245 static const ]b4_int_type_for([b4_pact
])[ pact_
[];
246 static const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
)[ pact_ninf_
;
247 static const ]b4_int_type_for([b4_defact
])[ defact_
[];
248 static const ]b4_int_type_for([b4_pgoto
])[ pgoto_
[];
249 static const ]b4_int_type_for([b4_defgoto
])[ defgoto_
[];
250 static const ]b4_int_type_for([b4_table
])[ table_
[];
251 static const ]b4_int_type(b4_table_ninf
, b4_table_ninf
)[ table_ninf_
;
252 static const ]b4_int_type_for([b4_check
])[ check_
[];
253 static const ]b4_int_type_for([b4_r1
])[ r1_
[];
254 static const ]b4_int_type_for([b4_r2
])[ r2_
[];
256 #if YYDEBUG || YYERROR_VERBOSE
257 static const char* const name_
[];
260 /* More tables, for debugging. */
262 static const RhsNumberType rhs_
[];
263 static const ]b4_int_type_for([b4_prhs
])[ prhs_
[];
264 static const ]b4_int_type_for([b4_rline
])[ rline_
[];
265 static const ]b4_int_type_for([b4_stos
])[ stos_
[];
266 static const ]b4_int_type_for([b4_toknum
])[ token_number_
[];
267 virtual void reduce_print_ (int yyrule
);
268 virtual void stack_print_ ();
271 /* Even more tables. */
272 static inline TokenNumberType
translate_ (int token
);
275 static const int eof_
;
276 /* LAST_ -- Last index in TABLE_. */
277 static const int last_
;
278 static const int nnts_
;
279 static const int empty_
;
280 static const int final_
;
281 static const int terror_
;
282 static const int errcode_
;
283 static const int ntokens_
;
284 static const unsigned user_token_number_max_
;
285 static const TokenNumberType undef_token_
;
292 /* Error handling. */
298 std::ostream
&cdebug_
;
300 /* Lookahead and lookahead in internal form. */
307 /* Semantic value and location of lookahead token. */
309 LocationType location
;
315 /* Initial location. */
316 LocationType initlocation_
;
317 ]b4_parse_param_vars
[
321 #endif /* ! defined PARSER_HEADER_H */]
323 @output @output_parser_name@
324 b4_copyright([C
++ Skeleton parser
for LALR(1) parsing with Bison
],
327 m4_if(b4_defines_flag
, 0, [], [#include @output_header_name@])[
329 /* Enable debugging if requested. */
331 # define YYCDEBUG if (debug_) cdebug_
332 # define YY_REDUCE_PRINT(Rule) \
335 reduce_print_ (Rule); \
337 # define YY_STACK_PRINT() \
343 # define YYCDEBUG if (0) cdebug_
344 # define YY_REDUCE_PRINT(Rule)
345 # define YY_STACK_PRINT()
346 #endif /* !YYDEBUG */
348 #define YYACCEPT goto yyacceptlab
349 #define YYABORT goto yyabortlab
350 #define YYERROR goto yyerrorlab
354 yy::]b4_parser_class_name
[::parse ()
359 /* Initialize the stacks. The initial state will be pushed in
360 yynewstate, since the latter expects the semantical and the
361 location values to have been already stored, initialize these
362 stacks with a primary value. */
363 state_stack_
= StateStack (0);
364 semantic_stack_
= SemanticStack (1);
365 location_stack_
= LocationStack (1);
371 location
= initlocation_
;
373 YYCDEBUG
<< "Starting parse" << std::endl
;
377 state_stack_
.push (state_
);
378 YYCDEBUG
<< "Entering state " << state_
<< std::endl
;
384 /* Try to take a decision without lookahead. */
386 if (n_
== pact_ninf_
)
389 /* Read a lookahead token. */
390 if (looka_
== empty_
)
392 YYCDEBUG
<< "Reading a token: ";
396 /* Convert token to internal form. */
401 YYCDEBUG
<< "Now at end of input." << std::endl
;
405 ilooka_
= translate_ (looka_
);
409 YYCDEBUG
<< "Next token is " << looka_
410 << " (" << name_
[ilooka_
];
412 YYCDEBUG
<< ')' << std::endl
;
417 /* If the proper action on seeing token YYTOKEN is to reduce or to
418 detect an error, take that action. */
420 if (n_
< 0 || last_
< n_
|| check_
[n_
] != ilooka_
)
423 /* Reduce or error. */
427 if (n_
== table_ninf_
)
442 /* Shift the lookahead token. */
444 YYCDEBUG
<< "Shifting token " << looka_
445 << " (" << name_
[ilooka_
] << "), ";
448 /* Discard the token being shifted unless it is eof. */
452 semantic_stack_
.push (value
);
453 location_stack_
.push (location
);
455 /* Count tokens shifted since error; after three, turn off error
463 /*-----------------------------------------------------------.
464 | yydefault -- do the default action for the current state. |
465 `-----------------------------------------------------------*/
467 n_
= defact_
[state_
];
472 /*-----------------------------.
473 | yyreduce -- Do a reduction. |
474 `-----------------------------*/
477 /* If LEN_ is nonzero, implement the default value of the action:
478 `$$ = $1'. Otherwise, use the top of the stack.
480 Otherwise, the following line sets YYVAL to garbage.
481 This behavior is undocumented and Bison
482 users should not rely upon it. */
485 yyval
= semantic_stack_
[len_
- 1];
486 yyloc
= location_stack_
[len_
- 1];
490 yyval
= semantic_stack_
[0];
491 yyloc
= location_stack_
[0];
496 Slice
< LocationType
, LocationStack
> slice (location_stack_
, len_
);
497 YYLLOC_DEFAULT (yyloc
, slice
, len_
);
499 YY_REDUCE_PRINT (n_
);
505 ]/* Line __line__ of lalr1.cc. */
506 b4_syncline([@oline@
], [@ofile@
])[
508 state_stack_
.pop (len_
);
509 semantic_stack_
.pop (len_
);
510 location_stack_
.pop (len_
);
514 semantic_stack_
.push (yyval
);
515 location_stack_
.push (yyloc
);
517 /* Shift the result of the reduction. */
519 state_
= pgoto_
[n_
- ntokens_
] + state_stack_
[0];
520 if (0 <= state_
&& state_
<= last_
&& check_
[state_
] == state_stack_
[0])
521 state_
= table_
[state_
];
523 state_
= defgoto_
[n_
- ntokens_
];
526 /*------------------------------------.
527 | yyerrlab -- here on detecting error |
528 `------------------------------------*/
530 /* If not already recovering from an error, report this error. */
531 report_syntax_error_ ();
535 /* If just tried and failed to reuse lookahead token after an
536 error, discard it. */
538 /* Return failure if at end of input. */
541 /* If at end of input, pop the error token,
542 then the rest of the stack, then return failure. */
547 semantic_stack_
.pop ();
548 location_stack_
.pop ();
549 if (state_stack_
.height () == 1)
551 // YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
552 // FIXME: yydestruct (yystos[*yyssp], yyvsp]b4_location_if([, yylsp])[);
558 YYCDEBUG
<< "Discarding token " << looka_
559 << " (" << name_
[ilooka_
] << ")." << std::endl
;
560 // yydestruct (yytoken, &yylval]b4_location_if([, &yylloc])[);
566 /* Else will try to reuse lookahead token after shifting the error
571 /*---------------------------------------------------.
572 | yyerrorlab -- error raised explicitly by YYERROR. |
573 `---------------------------------------------------*/
577 /* Pacify GCC when the user code never invokes YYERROR and the label
578 yyerrorlab therefore never appears in user code. */
583 state_stack_
.pop (len_
);
584 semantic_stack_
.pop (len_
);
585 location_stack_
.pop (len_
);
586 state_
= state_stack_
[0];
589 /*-------------------------------------------------------------.
590 | yyerrlab1 -- common code for both syntax error and YYERROR. |
591 `-------------------------------------------------------------*/
593 errstatus_
= 3; /* Each real token shifted decrements this. */
598 if (n_
!= pact_ninf_
)
601 if (0 <= n_
&& n_
<= last_
&& check_
[n_
] == terror_
)
609 /* Pop the current state because it cannot handle the error token. */
610 if (state_stack_
.height () == 1)
616 if (stos_
[state_
] < ntokens_
)
618 YYCDEBUG
<< "Error: popping token "
619 << token_number_
[stos_
[state_
]]
620 << " (" << name_
[stos_
[state_
]];
622 YYPRINT (stderr
, token_number_
[stos_
[state_
]],
623 semantic_stack_
.top ());
625 YYCDEBUG
<< ')' << std::endl
;
629 YYCDEBUG
<< "Error: popping nonterminal ("
630 << name_
[stos_
[state_
]] << ')' << std::endl
;
636 semantic_stack_
.pop ();
637 location_stack_
.pop ();
638 state_
= state_stack_
[0];
645 YYCDEBUG
<< "Shifting error token, ";
647 semantic_stack_
.push (value
);
648 location_stack_
.push (location
);
663 yy::]b4_parser_class_name
[::lex_ ()
666 looka_
= yylex (&value
, &location
);
668 looka_
= yylex (&value
);
672 /** Generate an error message, and invoke yyerror. */
674 yy::]b4_parser_class_name
[::report_syntax_error_ ()
676 /* If not already recovering from an error, report this error. */
683 if (pact_ninf_
< n_
&& n_
< last_
)
685 message
= "syntax error, unexpected ";
686 message
+= name_
[ilooka_
];
689 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
690 if (check_
[x
+ n_
] == x
&& x
!= terror_
)
695 for (int x
= (n_
< 0 ? -n_
: 0); x
< ntokens_
+ nnts_
; ++x
)
696 if (check_
[x
+ n_
] == x
&& x
!= terror_
)
698 message
+= (!count
++) ? ", expecting " : " or ";
706 message
= "syntax error";
712 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
714 const ]b4_int_type(b4_pact_ninf
, b4_pact_ninf
) yy::b4_parser_class_name::pact_ninf_
= b4_pact_ninf
[;
715 const ]b4_int_type_for([b4_pact
])[
716 yy::]b4_parser_class_name
[::pact_
[] =
721 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
722 doesn't specify something else to do. Zero means the default is an
724 const ]b4_int_type_for([b4_defact
])[
725 yy::]b4_parser_class_name
[::defact_
[] =
730 /* YYPGOTO[NTERM-NUM]. */
731 const ]b4_int_type_for([b4_pgoto
])[
732 yy::]b4_parser_class_name
[::pgoto_
[] =
737 /* YYDEFGOTO[NTERM-NUM]. */
738 const ]b4_int_type_for([b4_defgoto
])[
739 yy::]b4_parser_class_name
[::defgoto_
[] =
744 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
745 positive, shift that token. If negative, reduce the rule which
746 number is the opposite. If zero, do what YYDEFACT says. */
747 const ]b4_int_type(b4_table_ninf
, b4_table_ninf
) yy::b4_parser_class_name::table_ninf_
= b4_table_ninf
[;
748 const ]b4_int_type_for([b4_table
])[
749 yy::]b4_parser_class_name
[::table_
[] =
755 const ]b4_int_type_for([b4_check
])[
756 yy::]b4_parser_class_name
[::check_
[] =
762 /* STOS_[STATE-NUM] -- The (internal number of the) accessing
763 symbol of state STATE-NUM. */
764 const ]b4_int_type_for([b4_stos
])[
765 yy::]b4_parser_class_name
[::stos_
[] =
770 /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal token number corresponding
772 const ]b4_int_type_for([b4_toknum
])[
773 yy::]b4_parser_class_name
[::token_number_
[] =
779 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
780 const ]b4_int_type_for([b4_r1
])[
781 yy::]b4_parser_class_name
[::r1_
[] =
786 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
787 const ]b4_int_type_for([b4_r2
])[
788 yy::]b4_parser_class_name
[::r2_
[] =
793 #if YYDEBUG || YYERROR_VERBOSE
794 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
795 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
797 const yy::]b4_parser_class_name
[::name_
[] =
804 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
805 const yy::]b4_parser_class_name
[::RhsNumberType
806 yy::]b4_parser_class_name
[::rhs_
[] =
811 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
813 const ]b4_int_type_for([b4_prhs
])[
814 yy::]b4_parser_class_name
[::prhs_
[] =
819 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
820 const ]b4_int_type_for([b4_rline
])[
821 yy::]b4_parser_class_name
[::rline_
[] =
826 /** Print the state stack from its BOTTOM up to its TOP (included). */
829 yy::]b4_parser_class_name
[::stack_print_ ()
831 cdebug_
<< "state stack now";
832 for (StateStack::ConstIterator i
= state_stack_
.begin ();
833 i
!= state_stack_
.end (); ++i
)
834 cdebug_
<< ' ' << *i
;
835 cdebug_
<< std::endl
;
838 /** Report that the YYRULE is going to be reduced. */
841 yy::]b4_parser_class_name
[::reduce_print_ (int yyrule
)
843 unsigned int yylno
= rline_
[yyrule
];
844 /* Print the symbols being reduced, and their result. */
845 cdebug_
<< "Reducing via rule " << n_
- 1 << " (line " << yylno
<< "), ";
846 for (]b4_int_type_for([b4_prhs
])[ i
= prhs_
[n_
];
848 cdebug_
<< name_
[rhs_
[i
]] << ' ';
849 cdebug_
<< "-> " << name_
[r1_
[n_
]] << std::endl
;
853 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
854 yy::]b4_parser_class_name
[::TokenNumberType
855 yy::]b4_parser_class_name
[::translate_ (int token
)
858 const TokenNumberType
863 if ((unsigned) token
<= user_token_number_max_
)
864 return translate_table
[token
];
869 const int yy::]b4_parser_class_name
[::eof_
= 0;
870 const int yy::]b4_parser_class_name
[::last_
= ]b4_last
[;
871 const int yy::]b4_parser_class_name
[::nnts_
= ]b4_nterms_number
[;
872 const int yy::]b4_parser_class_name
[::empty_
= -2;
873 const int yy::]b4_parser_class_name
[::final_
= ]b4_final_state_number
[;
874 const int yy::]b4_parser_class_name
[::terror_
= 1;
875 const int yy::]b4_parser_class_name
[::errcode_
= 256;
876 const int yy::]b4_parser_class_name
[::ntokens_
= ]b4_tokens_number
[;
878 const unsigned yy::]b4_parser_class_name
[::user_token_number_max_
= ]b4_user_token_number_max
[;
879 const yy::]b4_parser_class_name
[::TokenNumberType
yy::]b4_parser_class_name
[::undef_token_
= ]b4_undef_token_number
[;
884 b4_copyright([Stack handling
for Bison C
++ parsers
], [2002, 2003])[
886 #ifndef BISON_STACK_HH
887 # define BISON_STACK_HH
893 template < class T
, class S
= std::deque
< T
> >
898 typedef typename
S::iterator Iterator
;
899 typedef typename
S::const_iterator ConstIterator
;
905 Stack (unsigned n
) : seq_ (n
)
911 operator [] (unsigned i
)
918 operator [] (unsigned i
) const
945 inline ConstIterator
begin () const { return seq_
.begin (); }
946 inline ConstIterator
end () const { return seq_
.end (); }
953 template < class T
, class S
= Stack
< T
> >
958 Slice (const S
& stack
,
959 unsigned range
) : stack_ (stack
),
966 operator [] (unsigned i
) const
968 return stack_
[range_
- i
];
978 #endif // not BISON_STACK_HH]
981 b4_copyright([Position
class for Bison C
++ parsers
], [2002, 2003])[
985 ** Define the Location class.
988 #ifndef BISON_POSITION_HH
989 # define BISON_POSITION_HH
996 /** \brief Abstract a Position. */
1000 /** \brief Initial column number. */
1001 static const unsigned int initial_column
= 0;
1002 /** \brief Initial line number. */
1003 static const unsigned int initial_line
= 1;
1005 /** \name Ctor & dtor.
1008 /** \brief Construct a Position. */
1011 line (initial_line
),
1012 column (initial_column
)
1018 /** \name Line and Column related manipulators
1021 /** \brief (line related) Advance to the COUNT next lines. */
1022 inline void lines (int count
= 1)
1024 column
= initial_column
;
1028 /** \brief (column related) Advance to the COUNT next columns. */
1029 inline void columns (int count
= 1)
1031 int leftmost
= initial_column
;
1032 int current
= column
;
1033 if (leftmost
<= current
+ count
)
1036 column
= initial_column
;
1041 /** \brief File name to which this position refers. */
1042 std::string filename
;
1043 /** \brief Current line number. */
1045 /** \brief Current column number. */
1046 unsigned int column
;
1049 /** \brief Add and assign a Position. */
1050 inline const Position
&
1051 operator+= (Position
& res
, const int width
)
1053 res
.columns (width
);
1057 /** \brief Add two Position objects. */
1058 inline const Position
1059 operator+ (const Position
& begin
, const int width
)
1061 Position res
= begin
;
1062 return res
+= width
;
1065 /** \brief Add and assign a Position. */
1066 inline const Position
&
1067 operator-= (Position
& res
, const int width
)
1069 return res
+= -width
;
1072 /** \brief Add two Position objects. */
1073 inline const Position
1074 operator- (const Position
& begin
, const int width
)
1076 return begin
+ -width
;
1079 /** \brief Intercept output stream redirection.
1080 ** \param ostr the destination output stream
1081 ** \param pos a reference to the Position to redirect
1083 inline std::ostream
&
1084 operator<< (std::ostream
& ostr
, const Position
& pos
)
1086 if (!pos
.filename
.empty ())
1087 ostr
<< pos
.filename
<< ':';
1088 return ostr
<< pos
.line
<< '.' << pos
.column
;
1092 #endif // not BISON_POSITION_HH]
1094 b4_copyright([Location
class for Bison C
++ parsers
], [2002, 2003])[
1097 ** \file location.hh
1098 ** Define the Location class.
1101 #ifndef BISON_LOCATION_HH
1102 # define BISON_LOCATION_HH
1104 # include <iostream>
1106 # include "position.hh"
1111 /** \brief Abstract a Location. */
1114 /** \name Ctor & dtor.
1117 /** \brief Construct a Location. */
1126 /** \name Line and Column related manipulators
1129 /** \brief Reset initial location to final location. */
1130 inline void step (void)
1135 /** \brief Extend the current location to the COUNT next columns. */
1136 inline void columns (unsigned int count
= 1)
1141 /** \brief Extend the current location to the COUNT next lines. */
1142 inline void lines (unsigned int count
= 1)
1150 /** \brief Beginning of the located region. */
1152 /** \brief End of the located region. */
1156 /** \brief Join two Location objects to create a Location. */
1157 inline const Location
operator+ (const Location
& begin
, const Location
& end
)
1159 Location res
= begin
;
1164 /** \brief Add two Location objects */
1165 inline const Location
operator+ (const Location
& begin
, unsigned width
)
1167 Location res
= begin
;
1168 res
.columns (width
);
1172 /** \brief Add and assign a Location */
1173 inline Location
&operator+= (Location
& res
, unsigned width
)
1175 res
.columns (width
);
1179 /** \brief Intercept output stream redirection.
1180 ** \param ostr the destination output stream
1181 ** \param loc a reference to the Location to redirect
1183 ** Avoid duplicate information.
1185 inline std::ostream
& operator<< (std::ostream
& ostr
, const Location
& loc
)
1187 Position last
= loc
.end
- 1;
1189 if (loc
.begin
.filename
!= last
.filename
)
1190 ostr
<< '-' << last
;
1191 else if (loc
.begin
.line
!= last
.line
)
1192 ostr
<< '-' << last
.line
<< '.' << last
.column
;
1193 else if (loc
.begin
.column
!= last
.column
)
1194 ostr
<< '-' << last
.column
;
1200 #endif // not BISON_LOCATION_HH]