[antlr-interest] Re: optional sub rules

Terence Parr parrt at jguru.com
Thu Feb 20 11:13:40 PST 2003


On Wednesday, February 19, 2003, at 10:43 AM, mklogic 
<mklogic at yahoo.com> wrote:

> I think you are right, the problem is probably my use of optional
> rule.
>
> I was trying to come up with a rule for XML Schema's "all" group,
> where all elements inside "all" may appear once or not at all.
> Assuming A,B, and C are elements that have minOccurs = 0, we will
> have the following rule. If we also assume minOccurs = 0 for "all"
> group itself, we will need to add ()* for zero or more according to
> antlr doc.
>
> Is what I am doing incorrect?
>
> all: ((A)? (B)? (C)?)*

not really...you have two optional paths for "all".  You need to 
delineate the possibilities i think:

all : A | A B | A B C | A C | B | B C | C | /* nothing */ ;

Ter
--
Co-founder, http://www.jguru.com
Creator, ANTLR Parser Generator: http://www.antlr.org
Lecturer in Comp. Sci., University of San Francisco


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list