%%.
The head section contains declarations, code support
and directives.
The grammar rules describing
the language - and the semantic actions that indicate how
evaluate the attributes associated with the symbols -
reside in the body section.
The tail section includes Perl code that gives support
to the semantic actions. Commonly
the lexical analyzer and error diagnostic subroutines
go there. In the case of eyapp the lexical analyzer
is usually automatically generated from the token definitions
or defined through a %lexer directive inside
the head section. Also,
for most cases, there is no need to overwrite the provided default
error diagnostic method.
%right '=' # Head section
%left '-' '+'
%left '*' '/'
%left NEG
%tree
%%
line: # Body section
sts <%name EXPS + ';'>
;
sts:
%name PRINT
PRINT leftvalue
| exp
;
exp:
%name NUM NUM
| %name VAR VAR
| %name ASSIGN leftvalue '=' exp
| %name PLUS exp '+' exp
| %name MINUS exp '-' exp
| %name TIMES exp '*' exp
| %name DIV exp '/' exp
| %name NEG
'-' exp %prec NEG
| '(' exp ')'
;
leftvalue : %name VAR VAR
;
%%