Re: grammar conflicts

Karsten Nyblad <148f3wg02@sneakemail.com>
31 Mar 2005 23:30:10 -0500

          From comp.compilers

Related articles
grammar conflicts jean.morissette666@videotron.ca (Jean Morissette) (2005-03-27)
Re: grammar conflicts 148f3wg02@sneakemail.com (Karsten Nyblad) (2005-03-31)
Re: grammar conflicts cfc@shell01.TheWorld.com (Chris F Clark) (2005-03-31)
Re: grammar conflicts xous@xouslab.com (Xous - Jose R. Negreira) (2005-03-31)
| List of all articles for this month |

From: Karsten Nyblad <148f3wg02@sneakemail.com>
Newsgroups: comp.compilers
Date: 31 Mar 2005 23:30:10 -0500
Organization: Compilers Central
References: 05-03-114
Keywords: parse, LALR

Jean Morissette wrote:
>I'm playing with JavaCUP and encounter some conflicts with my grammar (see
>below) and I don't know how to resolve these conflicts. Any help would be
>greatly appreciated.
>
> main ::=
> identifier_chain
> | qualified_asterisk
> ;
>
> identifier_chain ::=
> identifier_chain PERIOD identifier
> | identifier
> ;
>
> qualified_asterisk ::=
> asterisked_identified_chain PERIOD asterisk
> ;
>
> asterisked_identified_chain ::=
> asterisked_identified_chain PERIOD
> | identifier
> ;


Please note that in your grammar X...* would be a qualified_asterisk.
The whole trick is to make sure that the parser generator does not have
to decide if it is parsing an identifier_chain or a qualified_asterisk
before it has stacked identifier PERIOD since the next token, the token
in the window, will decide which of the two cases you are parsing.


Karsten Nyblad
148f3wg02 at sneakemail.com


main ::= identifier_chain
            | qualified_asterisk
            ;


identifier_chain ::= identifier
                                      | aux_identifier_chain
                                      ;


aux_identifier_chain ::= aux_identifier_chain PERIOD identifier
                                              | identifier PERIOD identifier
                                              ;


qualified_asterisk_chain ::= asterisk_identified_chain asterisk
                                                      ;


asterisk_identified_chain ::= asterisk_identified_chain PERIOD
                                                      | identifier PERIOD
                                                      ;



Post a followup to this message

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