[antlr-interest] How does one handle variable number of function parameters?

Rob Greene robgreene at gmail.com
Mon Nov 28 19:00:24 PST 2005


At work, I'm trying to get functions to work within expressions but I
have no clue how to handle the variable number of parameters (the
functions will be defined outside of the grammar file). The example
(the basic interpreter) doesn't explain what's going on, so is simply
baffling to me.

I've got my early prototype here at home (amazing how a lot of cool
work is done first at home!), and am identifying the function, but I'm
not sure how to pick up the parameters (which are expressions
themselves, of course).

What I'm expecting to be able to do is to fire a rule when the
argument/expression is evaluated, allowing me to add the result to a
list, for example. Then, when the function "executes", those
parameters are available. Note that the arguments must be evaluated
prior to the function being triggered.

I've included my sample from home. Evaluates expressions as double
(boolean reverts to zero being false and non-zero being true).
expression.g is the grammar and Main.java is my stupid test-bed.

Suggestions or pointers?

Thanks!
-Rob
-------------- next part --------------
A non-text attachment was scrubbed...
Name: expression.g
Type: application/octet-stream
Size: 2816 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20051128/14c12382/expression.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Main.java
Type: application/octet-stream
Size: 1174 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20051128/14c12382/Main.obj


More information about the antlr-interest mailing list