Buy the book!
|[ < ]||[ > ]||[ << ]||[ Up ]||[ >> ]||[Top]||[Contents]||[Index]||[ ? ]|
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
YYLLOC_DEFAULT macro is invoked each time a rule is
matched, before the associated action is run. It is also invoked
while processing a syntax error, to compute the error's location.
Most of the time, this macro is general enough to suppress location dedicated code from semantic actions.
YYLLOC_DEFAULT macro takes three parameters. The first one is
the location of the grouping (the result of the computation). When a
rule is matched, the second parameter is an array holding locations of
all right hand side elements of the rule being matched, and the third
parameter is the size of the rule's right hand side. When processing
a syntax error, the second parameter is an array holding locations of
the symbols that were discarded during error processing, and the third
parameter is the number of discarded symbols.
YYLLOC_DEFAULT is defined this way for simple
#define YYLLOC_DEFAULT(Current, Rhs, N) \ Current.first_line = Rhs.first_line; \ Current.first_column = Rhs.first_column; \ Current.last_line = Rhs[N].last_line; \ Current.last_column = Rhs[N].last_column;
and like this for GLR parsers:
#define YYLLOC_DEFAULT(Current, Rhs, N) \ Current.first_line = YYRHSLOC(Rhs,1).first_line; \ Current.first_column = YYRHSLOC(Rhs,1).first_column; \ Current.last_line = YYRHSLOC(Rhs,N).last_line; \ Current.last_column = YYRHSLOC(Rhs,N).last_column;
YYLLOC_DEFAULT, you should consider that:
|webmaster donations bookstore||delorie software privacy|
|Copyright © 2003 by The Free Software Foundation||Updated Jun 2003|