我写了以下语法:
分析器:
comparisons: (EQUALS | (GREATER EQUALS) | (LESS EQUALS) | LESS | GREATER);
词法:
EQUALS: '=';
GREATER: '>';
LESS : '<';
然而,ANTLR4警告我,我可以为比较创建一组令牌。我认为解析器更适合这个而不是词法分析器,因为解析器能够弄清楚:
1. > = (with spaces in between)
2. > a = (error as theres a identifier in the way)
您能否分享一下您在比较中的位置?