[antlr-interest] C# and '?' cardinality operator in AST rewrite rules
Benoit Miller
fulg at iname.com
Sat Jan 6 15:23:45 PST 2007
When targeting C#, and given the following grammar snippet:
foo : attrList? 'int' ID
-> ^(attrList? VAR_INT ID)
;
Antlr will generate parser code that references attrList no matter what
when building the AST. If attrList isn't present in the input, an
exception is thrown.
If I use '+' instead on attrList in the AST rewrite rule (keeping the
'?' in the rule itself), then it works fine.
Looking at http://www.antlr.org/wiki/display/ANTLR3/Tree+construction
implies that all cardinality operators (?, *, +) should work in AST
rewrite rules.
Is this a bug, or a feature?
Not really a problem since '+' works fine, I'm just wondering if I
understand this correctly. I'm using antlr-3.0b5.
Thanks,
Ben.
More information about the antlr-interest
mailing list