[antlr-interest] Yet another bug in ANTLRv4
Jan Finis
finis at in.tum.de
Tue Feb 28 08:29:32 PST 2012
Hi Ter,
I tried to change the "expr with concatenation" grammar to work without
using a doubly left-recursive concat operation ( expr : expr expr;)
in case that Honey Badger will never allow such rules again.
The resulting grammar is accepted by latest Honey Badger (the one pulled
from parrt/antlr). However, the resulting parser contains errors: an
unused semPred method with errors is produced. Since it is unused, I
simply deleted it. However, the parser still does not match the input
correctly. I guess both things have are symptoms of the same bug.
Here is (a simplified version of) the grammar producing the erroneous
parser:
rule returns [String r]
: t=ID ':' alts+=expr ('|' alts+= expr)* ';'
{ $r = "x"; }
;
strongExpr returns [String r]
: ID { $r = "x"; }
| '(' ep=parenExpr ')' { $r = "x"; }
| e1=strongExpr '?' { $r = "x"; }
;
expr returns [String r]
: e=strongExpr (e2=expr)? { $r = "x"; }
| e1=expr '->' ID {$r = "x"; }
;
parenExpr returns [String r]
: e1=expr '|' e2=parenExpr { $r = "x"; }
| expr {$r = $expr.r; }
;
ID : ('A'..'Z'|'a'..'z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
;
the resulting unused sempred with errors:
public boolean sempred(RuleContext _localctx, int ruleIndex, int
predIndex) {
switch ( ruleIndex ) {
case 1 : return strongExpr_sempred((StrongExprContext)_localctx,
predIndex);
case 2 : return expr_sempred((ExprContext)_localctx, predIndex);
}
return true;
}
the problems are the casts (StrongExprContext)_localctx and
(ExprContext)_localctx, since _localctx is a RuleContext here.
As mentioned, the sempred is not called anyway.
Best regards,
Jan
More information about the antlr-interest
mailing list