possible byacc/J bug?

mikesnare@hotmail.com (Mike Snare)
25 Jun 2004 01:54:56 -0400

          From comp.compilers

Related articles
possible byacc/J bug? mikesnare@hotmail.com (2004-06-25)
| List of all articles for this month |
From: mikesnare@hotmail.com (Mike Snare)
Newsgroups: comp.compilers
Date: 25 Jun 2004 01:54:56 -0400
Organization: http://groups.google.com
Keywords: yacc, question
Posted-Date: 25 Jun 2004 01:54:55 EDT

Note the following grammar:


/* 'a' ['b'|'c'] 'd'* */
stmt:
                TOKEN_A b_or_c opt_d NEWLINE {
                    // need $1, $2, $3 here
                }
        ;


/* mandatory 'b' or 'c' */
b_or_c:
                TOKEN_B
        | TOKEN_C
        ;


/* optional 'd' */
opt_d:
                TOKEN_D
        | { $$ = null; }
        ;


This grammar is valid and matches the following inputs as it should:
ab
abd
ac
acd


The problem is that when the epsilon rule is matched in opt_d (i.e.
there is no 'd'), the '$$ = null' action has the side effect of
setting the placeholder in valstk that should have 'b' or 'c' to null,
so that in the stmt production, the following values exist:
$1 = 'a'
$2 = 'null'
$3 = 'null'
$4 = '\n'


Only $3 should be null, and not $2 (it should be 'b' or 'c', depending
on the input). Is this a bug? Anyone know of a workaround?


-Mike Snare


Post a followup to this message

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