Professional Documents
Culture Documents
Phrase-level recovery
On discovering an error, perform a local fix to
allow the parser to continue.
Phrase-level recovery
Carefully filling in the blank entries about what to
do.
Yacc environment
Yacc processes the specification file and produce a y.tab.c file.
An integer function yyparse() is produced by Yacc.
Calls yylex() to get tokens.
Return non-zero when an error is found.
Return 0 if the program is accepted.
See example3.y
Symbol attributes
Each symbol can be associated with some
attributes.
Data structure of the attributes can be specified in the union in
the declarations. (see example4.y).
%union {
int semantic_value;
}
%token <semantic_value> ICONSTnumber
%type <semantic_value> exp
%type <semantic_value> term
%type <semantic_value> item
119
Semantic actions
Semantic actions associate with productions can be
specified.
item : LPARENnumber exp RPARENnumber
{$$ = $2;}
| ICONSTnumber
{$$ = $1;}
;
$$ is the attribute associated with the left handside of the
production
$1 is the attribute associated with the first symbol in the
right handside, $2 for the second symbol,
An action can be in anyway in the production, it is also
counted as a symbol.