[antlr-interest] Unknown method for CommonTreeNodeStream: getNodeIndex

Steven Raemaekers stevenraemaekers at gmail.com
Mon Feb 1 04:37:34 PST 2010


Hello,

I'm trying to make a tree walker for an if statement, in which the statement
part should of course only execute when the boolean expression part is true.
The problem is that in an example I found on the internet, I found that I
should use stream.push(...) and stream.pop() to insert tokens into
the stream that should be executed.

The problem is, getNodeIndex does not exist for CommonTreeNodeStream...but
how do I know the index which is needed for stream.push(index)?

ifstatement
@after {
 CommonTree expressionNode = (CommonTree)$ifstatement.start.getChild(0);
CommonTree instructionlistNode = (CommonTree)$ifstatement.start.getChild(1);
 if ($b.value == true)
{
 System.out.println("LogoTree.g, ifstatement evaluates to true");
CommonTreeNodeStream stream = (CommonTreeNodeStream)input;
 stream.push(stream.getNodeIndex(instructionlistNode));
                instructionlist();
                stream.pop();
}
}
: ^(IF b = booleanexpression .)
 ;

This does not work, since getNodeIndex does not exist for
CommonTreeNodeStream. Examples are rather scarce on the internet...something
this elemental should be more easy to implement, this has taken me days
now... Does anybody have any other ideas how to make an if statement? Any
help is greatly appreciated!


-- 
Regards,

Steven Raemaekers


More information about the antlr-interest mailing list