Contents | < Browse | Browse >
Special Features for Use in Actions
===================================
Here is a table of Bison constructs, variables and macros that are
useful in actions.
`$$'
Acts like a variable that contains the semantic value for the
grouping made by the current rule. Actions
`$N'
Acts like a variable that contains the semantic value for the Nth
component of the current rule. Actions
`$<TYPEALT>$'
Like `$$' but specifies alternative TYPEALT in the union specified
by the `%union' declaration. Action Types
`$<TYPEALT>N'
Like `$N' but specifies alternative TYPEALT in the union specified
by the `%union' declaration. Action Types
`YYABORT;'
Return immediately from `yyparse', indicating failure.
Parser Function
`YYACCEPT;'
Return immediately from `yyparse', indicating success.
Parser Function
`YYBACKUP (TOKEN, VALUE);'
Unshift a token. This macro is allowed only for rules that reduce
a single value, and only when there is no look-ahead token. It
installs a look-ahead token with token type TOKEN and semantic
value VALUE; then it discards the value that was going to be
reduced by this rule.
If the macro is used when it is not valid, such as when there is a
look-ahead token already, then it reports a syntax error with a
message `cannot back up' and performs ordinary error recovery.
In either case, the rest of the action is not executed.
`YYEMPTY'
Value stored in `yychar' when there is no look-ahead token.
`YYERROR;'
Cause an immediate syntax error. This statement initiates error
recovery just as if the parser itself had detected an error;
however, it does not call `yyerror', and does not print any
message. If you want to print an error message, call `yyerror'
explicitly before the `YYERROR;' statement. Error Recovery
`YYRECOVERING'
This macro stands for an expression that has the value 1 when the
parser is recovering from a syntax error, and 0 the rest of the
time. Error Recovery
`yychar'
Variable containing the current look-ahead token. (In a pure
parser, this is actually a local variable within `yyparse'.) When
there is no look-ahead token, the value `YYEMPTY' is stored in the
variable. Look-Ahead
`yyclearin;'
Discard the current look-ahead token. This is useful primarily in
error rules. Error Recovery
`yyerrok;'
Resume generating error messages immediately for subsequent syntax
errors. This is useful primarily in error rules. Error Recovery
`@N'
Acts like a structure variable containing information on the line
numbers and column numbers of the Nth component of the current
rule. The structure has four members, like this:
struct {
int first_line, last_line;
int first_column, last_column;
};
Thus, to get the starting line number of the third component, use
`@3.first_line'.
In order for the members of this structure to contain valid
information, you must make `yylex' supply this information about
each token. If you need only certain members, then `yylex' need
only fill in those members.
The use of this feature makes the parser noticeably slower.