Antlr4 - implicit definitions

I am trying to create a currently simple integer parser. At the moment I have:

grammar MyExpr;

input: (expr NEWLINE)+;


expr: '(' expr ')'
    | '-' expr
    | <assoc = right> expr '^' expr
    | expr ('*' | '/') expr
    | expr ('+' | '-') expr
    | ID '(' ExpressionList? ')'
    | INT;

ExpressionList : expr (',' expr)*; 


ID : [a-zA-Z]+;
INT : DIGIT+;
DIGIT: [0-9];
NEWLINE : '\r'?'\n';
WS : [\t]+ -> skip;

      

The ExpressionList rule seems to be causing some problems. If I remove everything containing the ExpressionList, everything compiles and seems to work fine. But as above, I get errors like:

error(160): MyExpr.g4:14:17: reference to parser rule expr in lexer rule ExpressionList
error(126): MyExpr.g4:7:6: cannot create implicit token for string literal in non-combined grammar: '-'

      

I am using Eclipse and Antlr4 Plugin. I try to target the cymbol grammar given in the antlr4 book.

Can someone tell me what's going on in my little grammar?

+3


source to share


1 answer


Found this myself:

Capitalized rules refer to Lexer rules. All I had to do was rename my ExpressionList to ExpressionList.



Maybe someone else will find this useful someday;)

+4


source







All Articles