declarations %% rules %% routines
THE DECLARATIONS SECTION may contain the following items.
RULES SECTION.
A rule has the form:
nonterminal : sentential form
| sentential form
.................
| sentential form
;
Actions may be associated with rules and are executed when
the associated sentential form is matched.
LEX-YACC INTERACTION
yyparse() calls yylex() when it needs a new token.
| LEX | YACC |
| return(TOKEN) | %token TOKEN |
| TOKEN is used in production |
%union {
(type fieldname)
(type fieldname)
...............
}
%token <fieldname> token %type <fieldname> non-terminal
yylval.fieldname = ...........
If you need a record type, then add it in the union. Example:
%union {
struct s {
double fvalue;
int ivalue;
} t;
}
yylval.t.ivalue = ......
$1.ivalue = ......assuming that $1 has the appropriate type, whatever it denotes.