I'm trying to implement a expression handling grammar (that deals with nested parenthesis and stuff). I have the following so far, but they can't deal with some cases (successful/failure cases appear after the following code block). Anyone know what's going on?
Note: The varname += and varname = stuff are just some additional AST generation helper stuff in XText. Don't worry about them for now.
...
NilExpression returns Expression:
'nil';
FalseExpression returns Expression:
'false';
TrueExpression returns Expression:
'true';
NumberExpression returns Expression:
value=Number;
StringExpression returns Expression:
value=STRING; //EllipsesExpression: '...';
//FunctionExpression: function=function; //don't allow random functions
UnaryExpression:
op=unop ('(' expr=Expression ')')|expr=Expression;
BinaryExpression:
'or'? AndOp; //or op
AndOp:
'and'? ComparisonOp;
ComparisonOp:
('>'|'<'|'>='|'<='|'=='|'~=')? ConcatOp;
ConcatOp:
'..'? AddSubOp;
AddSubOp:
('+' '-')? MultDivOp;
MultDivOp:
('*' '/')? ExpOp;
ExpOp:
'^'? (('(' expr=Expression ')')|expr=Expression);
ExprSideOne : Variable|NilExpression|FalseExpression|TrueExpression|
NumberExpression|StringExpression|UnaryExpression;
Expression:
(
'('
expression1=ExprSideOne expression2+=BinaryExpression*
')'
)
|
( expression1=ExprSideOne expression2+=BinaryExpression* )
;
...
And here's the list of parses/fails:
c = ((b)); //fails
c = ((a not b)); //fails
c = b; //parses
d = (b); //parses