Path: utzoo!attcan!uunet!husc6!mailrus!ames!joyce!sri-unix!garth!smryan From: smryan@garth.UUCP (Steven Ryan) Newsgroups: comp.lang.c Subject: Re: yacc with multiple attributes Message-ID: <859@garth.UUCP> Date: 2 Jul 88 21:35:14 GMT References: <16345@brl-adm.ARPA> <838@garth.UUCP> <18773@cornell.UUCP> Reply-To: smryan@garth.UUCP (Steven Ryan) Organization: INTERGRAPH (APD) -- Palo Alto, CA Lines: 33 >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).