[antlr-interest] Help with simple grammer.
Matthew Douglass
mdouglass at exapted.com
Thu Jun 12 23:41:37 PDT 2003
David,
I'm pretty new to all of this and I'm half replying so I can have others
check out my work, but I think you can change the definition of sequence to
element ('|' element)* and then remove pipeexpr to accomplish what you want
That should effectively define a sequence as an element followed by any
number (including 0) of pipe symbols and another element, giving you the
infinitely long sequences you want.
But like I said, I could be way off base here :)
Hope that helps,
Matthew
----- Original Message -----
From: "ooobles" <oobles at hotmail.com>
To: <antlr-interest at yahoogroups.com>
Sent: Thursday, June 12, 2003 6:56 PM
Subject: [antlr-interest] Help with simple grammer.
>
> I've been working on a grammer for a simple list based language. I
> have a problem with getting operator precedance right. Hopefully
> someone might spare a minute to help me out? I'm sure it can be
> solved simply. I'd like to create a grammer that can parse something
> like:
>
> definition: identA functionX( identB functionY( identC | identD |
> identE ) identF )
>
> there is only three real elements to the grammer.
> 1. a sequence.. A B C
> 2. a function.. F( )
> 3. an optional sequence.. A | B | C
>
> so far I've go a grammer like:
>
>
> definition: IDENTIFIER COLON sequence
> ;
>
> sequence: pipexpr ( sequence )?
> ;
>
> pipeexpr: element ( '|' pipeexpr )?
>
> element: IDENTIFIER
> | identifier '(' sequence ')'
> ;
>
>
> This will compile in Antlr without warnings. But it seems that the
> following would be parsed as valid
>
> def: identA | identB identC
>
> Is this case something that should be checked in code, or is there a
> better way to express the grammer?
>
> Thanks,
> David.
>
>
>
>
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list