Re: lex/yacc "bugs"

megatest! (Dave Jones)
10 Feb 92 23:07:56 GMT

          From comp.compilers

Related articles
lex/yacc "bugs" (1992-01-31)
Re: lex/yacc "bugs" megatest! (1992-02-10)
| List of all articles for this month |

Newsgroups: comp.compilers
From: megatest! (Dave Jones)
Keywords: yacc, errors
Organization: Megatest Corporation, San Jose, Ca
References: 92-02-008
Date: 10 Feb 92 23:07:56 GMT

I missed the original call-for-bugs. One that was discussed at great
length in this group a couple of years ago is related to error-recovery.
Many yaccs based on the original have this bug, which completely defeats
error-recovery using the ERROR token. Here is a test-file ("botch.y"):

%token a
s : oseq
oseq : /* empty */
| oseq a
| oseq error

Do a "yacc -vd botch.y", and look at the y.output file. If you see a state
which can shift "error", but has a default reduction, you have a buggy

EXAMPLE of buggy y.output:

        state 2
                s : oseq_ (1)
                oseq : oseq_a
                oseq : oseq_error

                error shift 4
                a shift 3
                . reduce 1

It seems that it can shift to state 4 on a (synthesized) error token, but
in fact it will do the default reduction (reduction 1) before the
error-token can be synthesized by the parser.

A properly working yacc would produce the following:

        state 2
                s : oseq_ (1)
                oseq : oseq_a
                oseq : oseq_error

                $end reduce 1
                error shift 4
                a shift 3
                . error

Notice that the default action is "error", not a reduction. The
error-action synthesizes the error-token, which can then be shifted.

If you have the original source, you can fix the file y3.c. Edit the line
which reads

if(temp1[1] > 0) lastred = 0;

Change it to say,

if( temp1[2] > 0 ) lastred = 0;

(The "2" stands for the error-token, the "1" for EOF.)

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.