Node:Location Default Action, Previous:Actions and Locations, Up:Locations
Actually, actions are not the best place to compute locations. Since locations
are much more general than semantic values, there is room in the output parser
to redefine the default action to take for each rule. The
YYLLOC_DEFAULT
macro is called each time a rule is matched, before the
associated action is run.
Most of the time, this macro is general enough to suppress location dedicated code from semantic actions.
The YYLLOC_DEFAULT
macro takes three parameters. The first one is
the location of the grouping (the result of the computation). The second one
is an array holding locations of all right hand side elements of the rule
being matched. The last one is the size of the right hand side rule.
By default, it is defined this way:
#define YYLLOC_DEFAULT(Current, Rhs, N) \ Current.last_line = Rhs[N].last_line; \ Current.last_column = Rhs[N].last_column;
When defining YYLLOC_DEFAULT
, you should consider that:
YYLLOC_DEFAULT
.
YYLLOC_DEFAULT
is executed, the output parser sets @$
to @1
.