[antlr-interest] Question about idiom.

Michael Richter ttmrichter at gmail.com
Sat Jan 9 23:17:50 PST 2010

2010/1/10 John B. Brodie <jbb at acm.org>

> > Think of it this way: you're declaring a variable.  You have a token for
> the
> > variable, then an optional type specification (A -- multiple tokens) and
> an
> > optional initializer (B -- multiple tokens).  Both parts are optional,
> but
> > you *must* have at least one and the declarations *must* be in the order
> of
> > type then initializer if both are present.  The only way I've found to do
> it
> > is (A | B | A B), but this is painful when A and B are more than one
> token
> > in length and I've got about 20 of these things in the grammar.  This is
> > just begging for typos.

> this example REALLY FAILS for me. It is hard for me to envision a
> language the can initialize a variable (e.g. B) without any declaration
> of that variable (e.g. A). So having a bare naked B under the above
> example makes no sense to me. Maybe you meant something like: (A B? C?)
> where A is the var decl, B is its type and C is its initial value...

That's what I said.  A token for the variable THEN an optional type
specification (A) and an optional initializer (B).  Three elements in total
with only two of them named.

I'll look over your other possible solutions there.  Having (A B? | B) looks
good enough especially since there's no left-commonality with A and B in ...
I think in any case, actually.

More information about the antlr-interest mailing list