[antlr-interest] variable number of arguments to a function

Michael Bedward michael.bedward at gmail.com
Wed Nov 25 03:24:49 PST 2009


Hello Siva,

Instead of have arguments or expressions explicitly in your function
rule, have an expression list rule.  The list is then the single
argument to the function.  That will take care of functions with any
number of arguments, including 0.

Example...

func_call       : ID LPAR expr_list RPAR -> ^(FUNC_CALL ID expr_list)
                ;

expr_list       : (expr (',' expr)* )? -> ^(EXPR_LIST expr*)
		;

That was taken from a grammar in one of my own projects...
http://jai-tools.googlecode.com/svn/trunk/jiffle/src/main/antlr3/jaitools/jiffle/parser/Jiffle.g

You can see plenty more examples in the grammars section of the ANTLR site.

Hope this helps.
Michael


More information about the antlr-interest mailing list