[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
10.1.3.3 User Defined Location Type
Instead of using the built-in types you may use the %define
variable
api.location.type
to specify your own type:
%define api.location.type {LocationType}
The requirements over your LocationType are:
- it must be copyable;
-
in order to compute the (default) value of
@$
in a reduction, the parser basically runs@$.begin = @$1.begin; @$.end = @$N.end; // The location of last right-hand side symbol.
so there must be copyable
begin
andend
members; - alternatively you may redefine the computation of the default location, in which case these members are not required (see section Default Action for Locations);
- if traces are enabled, then there must exist an ‘std::ostream& operator<< (std::ostream& o, const LocationType& s)’ function.
In programs with several C++ parsers, you may also use the %define
variable api.location.type
to share a common set of built-in
definitions for position
and location
. For instance, one
parser ‘master/parser.yy’ might use:
%defines %locations %define api.namespace {master::}
to generate the ‘master/position.hh’ and ‘master/location.hh’ files, reused by other parsers as follows:
%define api.location.type {master::location} %code requires { #include <master/location.hh> }
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on August 25, 2013 using texi2html 5.0.