parsing - ANTLR rewrite rules in grammar file -
i have rule looks this:
a : (b | c) d; b : 'b'; c : 'c'; d : 'd';
with grammar antlr builds flat parse tree. how can rewrite first rule (and leave other 2 unchanged) whatever matched being returned under root node called a?
if first production rule this:
a : b d;
then have been rewritten
a : b d -> ^(a b d)
and have solved problem. first grammar rule yields more 1 possibility resulting parse tree ^(a b d)
or ^(a c d)
.
how express when rewriting rule?
you can use ?
operator in rewrite follows.
a : (b | c) d -> ^(a b? c? d);
Comments
Post a Comment