06.01.2015 Views

Manual

Manual

Manual

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

68 Bison 2.3<br />

%pure-parser<br />

%lex-param {int *nastiness}<br />

/* Pure yyparse. */<br />

%parse-param {int *nastiness}<br />

%parse-param {int *randomness}<br />

results in the following signatures for all the parser kinds:<br />

int yylex (YYSTYPE *lvalp, YYLTYPE *llocp, int *nastiness);<br />

int yyparse (int *nastiness, int *randomness);<br />

void yyerror (YYLTYPE *locp,<br />

int *nastiness, int *randomness,<br />

char const *msg);<br />

The prototypes are only indications of how the code produced by Bison uses yyerror.<br />

Bison-generated code always ignores the returned value, so yyerror can return any type,<br />

including void. Also, yyerror can be a variadic function; that is why the message is always<br />

passed last.<br />

Traditionally yyerror returns an int that is always ignored, but this is purely for<br />

historical reasons, and void is preferable since it more accurately describes the return type<br />

for yyerror.<br />

The variable yynerrs contains the number of syntax errors reported so far. Normally this<br />

variable is global; but if you request a pure parser (see Section 3.7.10 [A Pure (Reentrant)<br />

Parser], page 58) then it is a local variable which only the actions can access.<br />

4.4 Special Features for Use in Actions<br />

Here is a table of Bison constructs, variables and macros that are useful in actions.<br />

$$<br />

$n<br />

[Variable]<br />

Acts like a variable that contains the semantic value for the grouping made by the<br />

current rule. See Section 3.5.3 [Actions], page 47.<br />

[Variable]<br />

Acts like a variable that contains the semantic value for the nth component of the<br />

current rule. See Section 3.5.3 [Actions], page 47.<br />

$$<br />

[Variable]<br />

Like $$ but specifies alternative typealt in the union specified by the %union declaration.<br />

See Section 3.5.4 [Data Types of Values in Actions], page 48.<br />

$n<br />

[Variable]<br />

Like $n but specifies alternative typealt in the union specified by the %union declaration.<br />

See Section 3.5.4 [Data Types of Values in Actions], page 48.<br />

YYABORT;<br />

[Macro]<br />

Return immediately from yyparse, indicating failure. See Section 4.1 [The Parser<br />

Function yyparse], page 63.<br />

YYACCEPT;<br />

[Macro]<br />

Return immediately from yyparse, indicating success. See Section 4.1 [The Parser<br />

Function yyparse], page 63.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!