I've got a String that represents a function call that I'm trying to parse. Each argument can either be another function call, or a single word. I would like to write an algorithm that will retrieve the name, and split the args.
class FunctionCall{
String name;
String[] args;
}
function parseFunction(String func){
FunctionCall fc = new FunctionCall();
fc.name = func.subString(0,func.indexOf("("))
fc.args = ???
}
A function call could look like func1(func2(arg1, arg2),func3(func4(arg3)),arg4)
, and I would like String[] args
to contain func2(arg1, arg2)
, func3(func4(arg3))
, and arg4
.
I don't believe this is possible with regex due to the recursive nature of function calls.
I writing the code in Java, but other languages would be fine.