[antlr-interest] Tree-based interpreters
Terence Parr
parrt at cs.usfca.edu
Wed Mar 25 10:48:19 PDT 2009
Hi. they use a custom AST node.
Ter
On Mar 25, 2009, at 9:58 AM, Joern Gebhardt wrote:
> Hi,
>
> I found in the wiki (http://www.antlr.org/wiki/display/CS652/Tree-based+interpreters
> ) a page that describes how an if-statement could be processed based
> on an AST.
>
> The grammar stated there looks like this:
>
> ifstat
> : ^('if' c=expr s=. e=.?) // ^('if' expr stat stat?)
> {
> int next = input.index();
> if ( ((Boolean)$c.value).booleanValue() ) {
>
> input.seek($s.start.streamIndex);
> stat();
> }
> else if ( $e!=null ) {
> input.seek($e.start.streamIndex);
> stat();
> }
> input.seek(next);
>
> }
> ;
>
> I tried this out but wasn't able to extract the "streamIndex" out of
> the statement CommonTree objects "s" and "e" (by the way, this is
> already stated as comment on the wiki).
> I only found was the "startIndex" and "stopIndex" but I guess that
> these attribute refer to the token position in the token stream
> created by the lexer.
>
> Is there any possibility to get the index of the
> CommonTreeNodeStream (and not the token stream)? Or do you have any
> other suggestions how I could use a tree-grammar
> to process if-statements?
>
> Thanks in advance,
> Joern
>
> 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