I have the grammar below (simplified for demonstration) and I'm having a problem in a particular case related to logical operators.
Everything I've test works except the case a logical operator is within my quoted identifier. For example this works:
@M = "ABC12345"
But this does not:
@M = "ABC12OR345"
What happens is the OR inside the string gives causes the following error
extraneous input 'OR' expecting {'"", LOWCHAR< HIGHCAR, DIGIT}
I'm at a loss as to how to get the precedence correct.
Thanks
grammar PRDL;
options
{
language=CSharp;
}
statement
: expression ( logicalOperator expression )*
;
logicalOperator
: logicalOR | logicalAND
;
logicalOR
: OR
;
logicalAND
: AND
;
expression
: mVar
| nVar
| parenStatement
| notExpression
;
parenStatement
: LPAREN statement RPAREN
;
notExpression
: NOT expression
;
mVar
: M equalityOperator quotedIdentifier
;
nVar
: N equalityOperator quotedIdentifier
;
equalityOperator
: EQUAL
;
quotedIdentifier
: '"' identifier '"'
;
identifier
: (HIGHCHAR | LOWCHAR | DIGIT)+
;
// ============ Lexer Defintions ========================
// OPERATORS
NOT_ALLOWED : '*' | '/' | '+' | '-' | '#' | '$' | '%' | '^';
EQUAL : '=';
COMMA : ',';
LPAREN : '(';
RPAREN : ')';
LPARENSQ : '[';
RPARENSQ : ']';
OR : ('OR' | 'or' | '||');
AND : ('AND' | 'and' | '&&');
NOT : ('NOT' | 'not' | '!') ;
M : '@M';
N : '@N';
LOWCHAR : 'a'..'z';
HIGHCHAR : 'A'..'Z';
DIGIT : '0'..'9';
// Whitespace -- ignored
WS : [ \n\t\r\f]+ -> skip;