Can this grammar be modified for lookahead of 1 ?

ssimmons@convex.com (Steve Simmons)
Thu, 18 Aug 1994 11:37:04 GMT

          From comp.compilers

Related articles
Can this grammar be modified for lookahead of 1 ? rahul@lsil.com (1994-08-15)
Can this grammar be modified for lookahead of 1 ? ssimmons@convex.com (1994-08-18)
Re: Can this grammar be modified for lookahead of 1 ? salomon@silver.cs.umanitoba.ca (1994-08-18)
Re: Can this grammar be modified for lookahead of 1 ? David=Cook%Diag%Mfg=Hou@bangate.compaq.com (1994-08-19)
| List of all articles for this month |
Newsgroups: comp.compilers
From: ssimmons@convex.com (Steve Simmons)
Keywords: parse, yacc
Organization: CONVEX News Network, Engineering (cnn.eng), Richardson, Tx USA
References: 94-08-098
Date: Thu, 18 Aug 1994 11:37:04 GMT

rahul@lsil.com (Rahul Bhargava x4596 ) writes:


> I am trying to generate a parser using yacc for the following grammar:
>
> s -> l (1)
> l -> L i F i e (2)
> i -> A | ACA | CA | AC | C (3)
> e -> C (4)


When you are in state "i", consumed an "A" and have "C" as a lookahead,
it is ambiguous because you don't know whether to reduce the "I" state or
shift the "C". YACC resolves shift-reduce conflicts by shifting.


Therefore, it cannot parse the following string although it is acceptable.


        "LAFAC"


To resolve this, you may wish to try the following:


s -> l (1)
l -> L i F ie (2)
i -> A | ACA | CA | AC | C (3)
ie -> AC | ACAC | CAC | ACC | CC (4)


Create a new production which is the concatenation of the "i" & "e"
productions.


Thank you.


Steve Simmons
--


Post a followup to this message

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