1
votes

I have started working on bison parser recently, Below is portion of the parser file , which will be executed in the loop.

      Program:  Start statement Stop
        {
        ...
        ...
        ...
        }

How to skip execution of the current case if any syntax error occurs in statement section? and continue the execution with the loop again?

    Program:  Start statement Stop
            {

               I want to skip execution of this part ..if any syntax error occurs in 
               any of the rule section ( Start, statement and Stop) 
            }

I have tried adding error rule like below but it is not working as expected.

        Program:  Start statement Stop
        {
         ....
          ...
          ...
        }

        | Program error Stop  (// skip until Stop)
        {
           yyerrok;
        }

what is the right way to handle the syntax error in this case? and continue the parsing?

Help is required here.

1
What loop? And what are Start and Stop? - rici
Actually that portion of the parser file is used to execute the test cases. Test case file is looks like START statements END... START statements END... And so on.. Start and Stop are the tokens to identify the keyword START and STOP. My question is if any syntax error occurrs in any one of the test case statement how to skip that test case and continue with other test cases. - Praveen Shetty

1 Answers

0
votes

I'm not sure that I really understand your needs, but something like the following should work:

test_cases : %empty
           | test_cases test_case
test_case  : START statements STOP
           | error STOP               { yyerrok; }

That's not very sophisticated; in particular, it will have unfortunate consequences if there is token in between START and STOP, and sub-optimal handling of a missing STOP token. (The ideal solution would be to resynchronize on START tokens as well, but then you'd have to arrange for the START token to be sent again by the scanner, which is ugly.)