If yacc / bison, a parsing error whenever possible disables the tool in error recovery mode. He will try to reset the tokens on his way to a "clean" state.
I cannot find the link for the lemon, so I cannot show any lemon code to fix this, but with yacc / bison, the rules could be used.
Namely, you need to adjust your error rule to indicate that the parser is ok with yyerrok so that it does not remove tokens. Then it will try to re-read the βbadβ token, so you need to clear it with yyclearin . Finally, since the rule attached to your error code contains the contents of your token, you will need to configure a function that will adjust your input stack by taking the current contents of the token and creating a new (correct) token with the same contents.
As an example, if a grammar defined as MyOther MyOther saw MyTok MyOther:
stack MyTok: "the text" MyOther: "new text" stack MyOther: "the text" MyOther: "new text"
To do this, learn yybackup . I cannot find an alternative method, although yybackup disapproving.
source share