Date: Mon, 28 Apr 1997 01:06:47 -0400 (EDT) From: Tim.Vanderhoek@X2296 To: FreeBSD-gnats-submit@freebsd.org Cc: robert.corbett@eng.Sun.COM Subject: bin/3403: yacc doesn't well parse recursivish errors Message-ID: <199704280506.BAA00878@X2296> Resent-Message-ID: <199704280520.WAA22852@hub.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 3403 >Category: bin >Synopsis: yacc doesn't well parse recursivish errors >Confidential: no >Severity: serious >Priority: low >Responsible: freebsd-bugs >State: open >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sun Apr 27 22:20:01 PDT 1997 >Last-Modified: >Originator: Tim Vanderhoek >Organization: The league of those who hack with yacc when they should be studying for their upcoming Bible test... >Release: FreeBSD 2.2-961006-SNAP i386 >Environment: Reasonably current yacc from FreeBSD-current... The yacc is more current than the Release line of this pr would suggest... >Description: It would seem that yacc doesn't properly handle rules along the lines of a: a error when multiple errors occur. Cc'd to robert.corbett@eng.Sun.COM (although I don't know if send-pr will strip that or not...) >How-To-Repeat: The following program should print out have the following output: -- Parsed #1 Parsed #0 -- However, it does not. Rather, only the first line ("Parsed #1") is printed... This is not what I want the program to do. It works correctly when one uses Bison (--version: GNU Bison version 1.25) to generate the parser. (If you try this, don't forget to give the -t argument to bison). Follows brief explanation of what goes wrong... It correctly shifts into state 1 (a : X . a error) for the first X, and then shifts into state 1 again for the second X. The Y token is returned and it correctly reduces an `a', and then an error, and finally reduces from state 5 (X a error .) all the way back to state 4 (X a . error) to finish off the first X statement. The error recovery correctly generates an error, however, this time it _DOES NOT_ shift from state 4 to state 5 on the error. Bison does exactly the same thing, except for the fact that it does shift on the second error the way it is supposed to... :) -- %{ #include <stdio.h> %} %union { int exp; } %token <exp> X %token Y %token NOSUCHTOKEN %token ERROR %% a: Y {} /* Hmm... can't use a simple "empty" here... */ | X a NOSUCHTOKEN {} | X a error { fprintf (stderr, "Parsed #%d\n", $1); } ; %% main () { yydebug = atoi(getenv("YYDEBUG") ? getenv("YYDEBUG") : ""); /* Bison */ yyparse (); } yylex () { static p = 0; const int tok[] = {X, X, Y, ERROR, ERROR, ERROR, 0}; if (tok[p] == X) yylval.exp = p; return tok[p++]; } yyerror() {} -- >Fix: Heh. My head's still spinning after spending most of today tracing this one down... >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199704280506.BAA00878>