antlr4 - Why is this left-recursive and how do I fix it? -
i'm learning antlr4 , i'm confused @ 1 point. java-like language, i'm trying add rules constructs member chaining, that:
expr1.methodcall(expr2).methodcall(expr3);
i'm getting error, saying 2 of rules mutually left-recursive:
expression : literal | variablereference | lparen expression rparen | statementexpression | memberaccess ; memberaccess: expression dot (methodcall | fieldreference);
i thought understood why above rule combination considered left-recursive: because memberaccess
candidate of expression
, memberaccess
starts expression
.
however, understanding broke down when saw (by looking @ the java example) if move contents of memberaccess
expression
, got no errors antlr4 (even though still doesn't parse want, seems fall loop):
expression : literal | variablereference | lparen expression rparen | statementexpression | expression dot (methodcall | fieldreference) ;
- why first example left-recursive second isn't?
- and have parse initial line?
the second left-recursive not mutually left recursive. antlr4 can eliminate left-recursive rules inbuilt algorithm. cannot eliminate mutually left recursive rules. there exists algorithm, hardly preserve actions , semantic predicates.
Comments
Post a Comment