yacc with multiple attributes

Steven Ryan smryan at garth.UUCP
Sun Jul 3 07:35:14 AEST 1988


>Yacc will choke on:
>
>prod:
>   a { fiddle something } b c { first result }
> | b { identical fiddle } b c { different result }
> ;

Do you mean?

    prod -> a {sem1} b {sem2} | a {sem3} c {sem4}

I would expect

    prod -> a $1 b {sem2} | a $2 c {sem4}
    $1   ->    {sem1}
    $2   ->    {sem3}

So given the items 'prod->a.$1 b' and 'prod->a.$2 c' it would then add
the items '$1->.' and '$2->.' which is a reduce/reduce conflict in
LR(0). Computing followers gives FOLLOWS($1)='b' and FOLLOWS($2)='c'. A
one symbol lookahead through the null production resolves the conflict.
Reduce to $1 and execute sem1 if the lookahead is b, and $2 with sem3 if
c.

The problem is not whether the grammar is LR(1) but is Yacc? It is generally
advertised as LR but sometimes the fine print says LALR. All too often LR
does not mean full LR(k) or even LR(1), but LALR, SLR, ....

Of course

    prod -> a $1 b c | a $2 b d

is LR(2) rather than LR(1).



More information about the Comp.lang.c mailing list