Yacc actions
Yacc actions are specified in curly braces and can be given anywhere in the definition section but it is a good practice to specify them after the last symbol.
Value of symbols:
All symbols are aa grammar rule :-? with a value associated with it.For terminal symbols the value can be asigned by the lexical analyzer.Non terminals symbols can have values associated with them using parser actions,they can be text,numbers or any kind of data structure.
The dollar sign is used to access value of symbol. $$ is the value of symbol associated with the left of the rule.$1, $2, $3 and $n refer to 1st,2nd ,3rd and nth symbol to the right of the rule.
A : '(' B ')'
{
othello( 1, "abc" );
}
;Value of symbols:
All symbols are aa grammar rule :-? with a value associated with it.For terminal symbols the value can be asigned by the lexical analyzer.Non terminals symbols can have values associated with them using parser actions,they can be text,numbers or any kind of data structure.
The dollar sign is used to access value of symbol. $$ is the value of symbol associated with the left of the rule.$1, $2, $3 and $n refer to 1st,2nd ,3rd and nth symbol to the right of the rule.
expr : '(' expr ')'
{
$$ = $2 ;
}

0 Comments:
Post a Comment
<< Home