You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
VarsDecl.g4 describes the syntax of variable declarations, such as int a, b, c.
grammar VarsDecl;
decl : type vars ;
type : 'int' # IntType
| 'float' # FloatType
;
vars : left = vars ',' ID # VarsList
| ID # VarsID
;
ID : [a-z]+ ;
WS : [ \t\r\n]+ -> skip ;
VarsDeclAG.g4 is the version of VarsDeclAG.g4 with parameters of rules and and embedded actions.
grammar VarsDeclAG;
decl : type vars[$type.text] ;
type : 'int'
| 'float'
;
vars[String typeStr]
: left = vars[$typeStr] ',' ID { System.out.println($ID.text + " : " + $typeStr); }
| ID { System.out.println($ID.text + " : " + $typeStr); }
;
ID : [a-z]+ ;
WS : [ \t\r\n]+ -> skip ;
I suspect it's related to #564 and similar issues. This is because ANTLR expects only simple terms in alternatives of left-recursive rule. In your case ANTLR can't handle left = vars[$typeStr] because it has a label (left) or [$typeStr] syntax.
VarsDecl.g4
describes the syntax of variable declarations, such asint a, b, c
.VarsDeclAG.g4
is the version ofVarsDeclAG.g4
with parameters of rules and and embedded actions.However, ANTLR 4 (version antlr 'org.antlr:antlr4:4.13.1') reports that
in VarsDeclAG.g4: rule vars is left recursive but doesn't conform to a pattern ANTLR can handle
(no errors inVarsDecl.g4
).The comments on StackOverflow (thanks to Bart Kiers) suggest that it may be a bug in translateLeftRecursiveRule.
The text was updated successfully, but these errors were encountered: