My problem is that the message passed to yyerror is already formatted (i.e. it is actually an English explanation what went wrong), and what I would like to get is just the current token (i.e. the one before the error pseudo-token).
So how to get it?
I use gplex/gppg which are lex/yacc implementations in C#.
I am sorry for not being 100% precise — what I need is token (symbol) not the body (text) which was matched (by the token).
Let’s say I have a rule [A-Za-z0-9_]+ constitutes an ID. So I would like to get token ID not a foobar.
There’s no standard, but bison and most versions of yacc store the current token in
yychar. Unfortunately, this is generally a local variable (ofyyparse), so you can’t access it in other functions (such asyyerror), only in parser actions.It might be helpful if you say WHY you want the current token — its not generally a useful peice of information. You mention the error pseudo-token, which makes no sense as that is associated with error recovery, not errors as such — by the time it comes into the picture normally a bunch of tokens from the input have been discarded.