I have a grammar that I'd like to include multi-parameter functions in (like f(x,y)
). I'm using AST output with my own tree parser. Right now my parameter list production is
paramdefs: (ID COMMA)* ID ;
This works fine, but the AST output for
z(x,y)=expression
is
(FUNC (z)(x)(,)(y)(expression))
(i.e. it's very flat).
The FUNC
CommonTree's children, in the general case, are {function name
, parameter
, comma
, parameter
, defined expression
}, for any number of parameters. I'd like the parameter list to be a single child and not have commas (this would make it easier to walk the tree).
Ideally, this is what the tree would look like:
(FUNC (z)((x)(y))(expression))
(note the absence of the comma element and the grouping of x
and y
.
Relevant associated areas of the grammar:
funcdef: ID '(' paramdefs ')' '=' expr -> ^(FUNC ID paramdefs expr) ;
paramdefs: (ID COMMA)* ID ;