[antlr-interest] input.TokenStream is null
Dominik Halfkann
dominik.halfkann at googlemail.com
Tue Jul 5 18:06:38 PDT 2011
I'm trying to make a TreeWalker for a tree like this:
input: int x = 3
output AST: ^(VARDEF int x 3)
My parser works just fine and also generates an AST like shown above, but
whenever I want to resolve anything from the AST, like with
$variableType.text, there is allways a NullReferenceException in the
generated C# 2.0 TreeWalker.
My TreeWalker:
tree grammar SGLTreeWalker;
options {
tokenVocab = SGL;
language = 'CSharp2';
}
[...]
compilationUnit
: (statement)+
;
statement
: variableDefinitionList
;
variableDefinitionList
: ^(VARDEF variableType variableName expression) {
Console.WriteLine($variableType.text); }
;
The problematic generated part looks like this:
Match(input, Token.UP, null);
Console.WriteLine(((variableType1 != null) ? input.TokenStream.ToString(
input.TreeAdaptor.GetTokenStartIndex(variableType1.Start),
input.TreeAdaptor.GetTokenStopIndex(variableType1.Start)) : null));
It turns out that input.TokenStream is null so it throws
the NullReferenceException. I read that this can happen if the
used TreeNodeStream isn't buffered, but I used the CommonTreeNodeStream so
it should be buffered I think. Any idea on what's going wrong?
More information about the antlr-interest
mailing list