I am having trouble with a no viable alternative at input sqr( with the following rules.
function_invocation : ID LPAREN term (',' term)* RPAREN ;
function_signature : ID LPAREN ID (',' ID)* RPAREN ;
term : function_invocation #functionTerm
| number #numberTerm
| string #stringTerm
| ID #idTerm
;
ID : ('a'..'z')('a'..'z'|'A'..'Z'|'0'..'9'|'_')* ;
I use function_signature in other rules where I only want ID to be valid such as:
function_definition : function_signature '=>' expression (','NL expression)* '.'NL ;
should parse:
sqr(x) => x * x,
x + 1.
And I use function_invocation where I want to allow more than just ID.
function_assignment : ID '=>' function_invocation ;
should parse:
z = sqr(3)
The problem is that ID is a valid term.
Make it so
function_signaturecan only be used when inside afunction_definition. In other words, drop that rule altogether, and writeThis way, the
=>terminal can be used to avoid the ambiguity. Alternatively, just put the=>terminal in thefunction_signature:Of course, I'm assuming here there's no other place in your grammar that allows a
function_invocationfollowed by a=>, but that would probably make the whole language ambiguous.