I am trying to define a simple functional language grammar, I am almost done with my definitions, but I can't get past the following ambiguities.
[14:43:53] warning(200): mygrammar.g:14:11: Decision can match input such as "ATOM" using multiple alternatives: 1, 2 As a result, alternative(s) 2 were disabled for that input
[14:43:53] warning(200): mygrammar.g:14:11: Decision can match input such as "ID" using multiple alternatives: 1, 2 As a result, alternative(s) 2 were disabled for that input
here are what I think are the relevant rules the drawing is almost identical for ATOM and ID:
program : (statement'.')* ;
statement : assignment
| expression;
assignment : func '->' statement ((','statement)=> ',' statement)*
| ID '->' expression
| ATOM '->' ( string | number );
func : (ID '(' args ')')=> ID '(' args ')';
term : func
| '(' expression ')'
| number
| string
| ID
| ATOM ;
ATOM : ('A'..'Z'|'_')+;
ID : ('a'..'z'|'_')('a'..'z'|'A'..'Z'|'0'..'9'|'_')*;
here is the syntax tree from ANTLRWorks
id alternatives http://www.vertigrated.com/images/id_alternatives.png
Here is a rough straw man of what I am trying to support parsing.
hypotenuse(a,b) ->
sqr(x) -> x * x,
sqr(sqr(a) + sqr(b)).
print(hypotnenuse(2,3)).
so I need to be able to support nesting statements
inside of functions
where ->
is my assignment operator, this is a single assignment language
where .
is my statement end marker
Is this even possible to parse with ANTLR3?