While creating the built-in interpreter of the ANTLR tree grammar, I ran into the problem of the multiplicity of arguments to the procedure call.
Consider the following (erroneous) definition of a grammar tree.
procedureCallStatement : ^(PROCEDURECALL procedureName=NAME arguments=expression*) { if(procedureName.equals("foo")) { callFooMethod(arguments[0], arguments[1]); }elseif(procedureName.equals("bar")) { callBarMethod(arguments[0], arguments[1], arguments[2]); } } ;
My problem is retrieving the given arguments. If there were a known number of expressions, I would simply assign the values ββthat come out of these expressions to my own variable, for example:
procedureCallStatement : ^(PROCEDURECALL procedureName=NAME argument1=expression argument2=expression) { ... } ;
This, however, is not the case.
For a case like this, what is the recommendation for interpreting the variable number of tree nodes within a row in an ANTLR tree grammar?
source share