[antlr-interest] Some Problem with tree parser
femtowin1
femtowin1 at gmail.com
Mon Apr 30 01:58:23 PDT 2007
Hi, while trying the following tree grammar:
tree grammar Rubyv3Tree;
options {
tokenVocab=Rubyv3; // reuse token types
ASTLabelType=CommonTree; // $label will have type CommonTree
}
@header {
package com.xruby.compiler.parser;
import com.xruby.compiler.codedom.*;
}
program returns[Program p]
@init{List statements=new ArrayList();}: ^(STATEMENT_LIST s=statement* {statements.add($s);}) {p=new Program(statements);} ;
statement returns[String s]
: ^(STATEMENT 'expression0') {s="expression0";};
------------------------------------------
actually the STATEMENT_LIST Tree will contains 0 or more statement, but the problem is, I can't collect value return from statement*, (Program is a class defined by me and not related to antlr).
I've tried s+=statement*, statement{statements.add($statement)}* (antlr reports and error when generating parser)
or statement{statements.add(statement)}*,
the problem is that in final generating code,
it is always like this:
switch (alt1) {
case 1 :
// C:\\toolset\\ruby\\xruby-trunk\\src\\com\\xruby\\compiler\\parser\\Rubyv3Tree.g:14:61: statement
{
pushFollow(FOLLOW_statement_in_program45);
statement(); //here
_fsp--;
}
break;
default :
break loop1;
}
} while (true);
without any code collection the value returned from
statement, it is weird and anybody knows what the problem is or is it an antlr bug? Thanks.
______________________________________
Sent from my www.pageflakes.com startpage
More information about the antlr-interest
mailing list