[antlr-interest] Re: Runtime rule multiplicity

Matthew Mastracci matthew at mastracci.com
Fri May 12 15:54:57 PDT 2006


Terence Parr wrote:

> ( {count<=max}?=> ID)?

I guess once the rule parameters are implemented, this might work (I 
omitted nested function calls for brevity):

statement
         : ID <parameter(0, resolveParameterCount($ID.text))>;

parameter(int current, int max)
         : NUMBER ( {current < max}? => <parameter(current + 1, max)> );

In the meantime, I suppose it might be possible to use inline code to 
push and pop parameter counts on a member Stack and use them:

@members {
         Stack<int> current = new Stack<int>();
         Stack<int> max = new Stack<int>();
}

statement
         : ID { current.push(0); 
max.push(resolveParameterCount($ID.text)); }
                 parameter;

parameter
         : NUMBER ( {current.peek() < max.peek()}? => {
                  current.push(current.pop + 1); } parameter|statement );




More information about the antlr-interest mailing list