Reputation: 147
I'm creating a language with ANTLR4. I'm trying to make possible to pass function as method's parameter. But I'm unable to find ane resources. Maybe someone could give a hint or resources if there are any available?
My end goal:
public int function1()
{
int a = function2(function3(1));
}
public int function2(int i)
{
return i + 1;
}
public int function3(int i)
{
return i+1;
}
Upvotes: 0
Views: 115
Reputation: 170148
A function call would simply be an alternative in your expression rule:
expression
: expression ( '+' | '-' ) expression
| INTEGER
| IDENTIFIER
| functionCall
;
functionCall
: IDENTIFIER '(' arguments? ')'
;
arguments
: expression ( ',' expression )*
;
Upvotes: 1