[antlr-interest] Runtime rule multiplicity

Matthew Mastracci matthew at mastracci.com
Fri May 12 12:59:37 PDT 2006


Is it possible in ANTLR3 to generate rules that have a multiplicity
determined at runtime?  For instance, in a grammer where parameters and
functions are somewhat ambiguous (ie: not delimited in any way), you may
have something like this:

func1 1 func2 2

At run-time, it would be determined that func1 has two parameters: "1"
and "func2 2".  For another run it might be determined that func1 has
three parameters and func2 has none.

So far, it looks like the only solution to this problem is to run the
lexer to get a list of tokens and generate a hand-rolled parser to
process it.

After reading through the ANTLR blogs, I suppose it might also be 
possible to use a gated semantic predicate to  continue the rule iff 
there are remaining parameters, or the optional subrules stuff, but I'm 
not entirely sure what the syntax of these would look like.  Are there 
any examples?

Any suggestions? I'd like to use ANTLR for both the parser and the 
lexer, if possible.

Matt.



More information about the antlr-interest mailing list