eliminate '++' unary operator in antlr lexer

85 Views Asked by At

I'm new to antlr3, and I'm trying to write a lexer that accept '+' and '-' as a special symbol but when see '++' operator it should treat it as a error but I don't know how to implement it, now with below specification it tokenize '++' as two token '+' and '+'.

SPECIALSYMBOL: ('+'|'-');
1

There are 1 best solutions below

0
On

Keep your SPECIALSYMBOL as it is and handle the case in the parser rules : if you do not allow repeated SPECIALSYMBOL in your rules, a ++ should produce an error.