Greetings!
On Fri, 2010-03-19 at 15:26 -0400, William Koscho wrote:
> 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;
>
I believe your interfaceType parser rule does not initialize the text of
the token it creates for the tree node. You should be able to inspect
the generated code and verify this....
I believe you want your interfaceType parser rule to be:
interfaceType :
( k='provides' -> PROVIDES[$k] )
| ( k='requires' -> REQUIRES[$k] )
;
if i recall correctly, using the [] stuff sets both the text and the
location of the generated virtual token.
and oh by the way are you sure you really need the virtual tokens?
hope this helps...
-jbb
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en.