c - Recovering error tokens in parsing (Lemon) -


I am using lemon as a parser generator, its error handling is similar to yak and bison if you do not know Is lemon

An option to define an error token in the set of lemon rules to catch parsing errors is to destroy the token due to the default behavior error of the generated parser; Is there a way to override this behavior, so that I can keep the token?

An example to show what is happening: Basically I'm adding tokens with each rule to improve the input string. Example grammar:

  Input :: = string (A) {printf ("% s", A); } // print string (a) :: print = print (b) part (c) {a = attachment (b, c); } String (A) :: = Part (B) {A = B; } Part (A) :: = NUMBER (B) NAME (C) {A = Annex (C, B); } // Restore part of the number and name (A) :: = error (B). {A = B; } // token on error anyway  

:

  "username 1234 joseph"  

find me Output:

  "joseph 1234"  

Because the text "username" is parted by the parser (A) :: Junk in error (b) The rule is, but in reality I want to:

  "User Name Joseph 1234" as the output.  

If you can solve this problem in Bison or other parser generator, I accept it as an answer.

With yacc / bison, drop the tool into a parsing error error recovery mode, if possible. It will try to relinquish tokens on the path of "clean" state

I can not find any reference to lemon, so I can not show some lemon code to fix it, but yacc / bison With, the rules will be used.

That is, you need to adjust your error rule to prevent it from going token to fix it with

parser yyerrok After this, it will try to redo the "bad" token again, so you have to clear it with yyclearin Finally, since the rule associated with your error code contains the contents of your token, you Taking the existing token content and the same content By making token a new (right) with Ri must set the function to adjust the input stack.

For example, if a grammar is defined as MyOther MyOther has seen MyTok MyOther:

  Matlock Stack: "Text" MyOther: " New text "Stack MyOther:" the lesson "MyOther:" New Text " 

To complete this, check to use. I am unable to find an alternate method, although frowned on yybackup .


Comments