Declare the tokens with an alias:
%token <id> IDENTIFIER "identifier"
%token RPAREN "right parenthesis"
The %printer
function wouldn't be used in an error message, even if it were implemented in Java, because the error is talking about tokens which have not been encountered, whereas the %printer
method is used to print the semantic value of tokens which were encountered. The unencountered token does not exist, and therefore its semantic value cannot be printed, only its description.