[antlr-interest] THelp w/ Tree Grammer - Rule Action Error

William Koscho wkoscho at gmail.com
Fri Mar 19 12:26:41 PDT 2010


Hi All,

I have a tree grammar, and am trying to just print out some information from
the tree.  This works fine for matching tokens, but not when matching the
rules.  I'm hoping someone can help explain why this is giving me a
NullPointerException and how to correct it:

Tree Grammar:

// the $i.text causes the NullPointerException, when I $i.text, it works
fine
interfaceDeclaration:  ^(i=interfaceType ID) { System.out.println($i.text +
": " + $ID.text); };

interfaceType:
   PROVIDES
 | REQUIRES;

Corresponding Parser Grammar:

interfaceDeclaration:   interfaceType ID -> ^(interfaceType ID);
interfaceType:
   'provides' -> PROVIDES
 | 'requires' -> REQUIRES;

Thanks very much,
Bill


More information about the antlr-interest mailing list