error recovery in yacc

error recovery in yacc

Post by Shiladitya Biswas mt cs » Tue, 14 Jan 2003 07:44:02



Hi
I wanted to know if I can in some way recover all the tokens in the stack
and print them in case  an error occurs in the input.I want all the
currently lined up tokens for further processing and terminate the parsing
there.
        I am using bison and berkely yacc
thanks

--
Shiladitya Biswas
MTech CSE
[You'll probably have to fiddle the parser somewhat, because it may have
made some default reductions before noticing the error. -John]

 
 
 

1. yacc/bison error recovery

Suppose my grammar is:

s       : e { printf("%d\n", $1); }
        ;

e
        : 'x'           { $$ = 0; }
        | 'x' '-' e     { $$ = $3 + 1;}
        |  error '-' e  { $$ = $3 + 1;}
        ;

I.e. input consists of a list of identifiers 'x' separated by hyphens,
and the program should count and print the number of hyphens. The
error rule states that there may be incorrect identifiers, but
regardless we expect the number of hyphens to be counted.

For the input "x-x-y-x-x-xy-y-y-x-x", which contains some incorrect
identifiers, I would expect output "9", i.e. the number of hyphens,
but instead the parser prints two (!) numbers, viz.  "5" and "4",
resp. How can this be?  Is the parser implicitly restarted in the
middle of the input?  I only call yyparse() once.

It seems to me that incorrect identifier "y" is dealt with as
expected, but something strange happens when encountering "xy". If I
add more occurrences of "xy" to the input string, the parser prints
even more numbers (adding up to the total number of hyphens in the
input). "yx" is treated just like "y", i.e. in the expected way of
reducing to "error".

PS yacc and bison behave exactly the same here.
Thanks in advance,
 Mark-Jan Nederhof
[When yacc is in its error state it pops states off the stack until it
can resynchronize.  Looks like it popped all the way up to the root.
-John]

2. FS:CND/US A500 1MB

3. Error recovery using flex and yacc

4. Forms

5. Memory leaks upon error recovery in Yacc

6. Are these two VB.NET statements equivalent?

7. Unusual error recovery in Yacc parser

8. REQ: Computer keyboard font

9. Yacc error recovery...

10. Error Recovery in Yacc

11. More yacc error recovery questions...

12. Q: Error detection/recovery in LEX/YACC (Help)

13. yacc error recovery