[antlr-interest] Unknown method for CommonTreeNodeStream: getNodeIndex
Terence Parr
parrt at cs.usfca.edu
Mon Feb 1 10:34:43 PST 2010
Hi Steven, I'd recommend staying away from tree-based interpreters that need to jump around. The code samples for my book, which are free, gives you an example though. I've moved away from that node Index stuff.
Ter
On Feb 1, 2010, at 4:37 AM, Steven Raemaekers wrote:
> 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
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
More information about the antlr-interest
mailing list