[antlr-interest] AST factory / heterogeneous tree enhancement
Terence Parr
parrt at jguru.com
Fri Oct 18 18:17:47 PDT 2002
Ok, Loring and I have discussed the tree factory problems.
"micheal_jor" <open.zone at virgin.net> brought them up regarding C# and
Ric seems to have fixed this for C++. So, now the Java solution.
Here is the problem as I understand it.
1. #[FOO] always builds an AST node of the default type because
the ASTFactory only knows about the default. In future if you say
tokens {
PLUS<AST=PLUSNode>;
...
}
then I'll make action #[PLUS] create the right node. You can also
say
#[ID,"foo","VarNode"] (3rd arg is the type of node to create).
2. dup methods of ASTFactory don't respect the type of the nodes; it
uses default node type. In future, i'll use
t.getClass().newInstance()
to do the dup.
3. hetero tree construction does not call the factory. E.g.,
anIntRule : INT<AST=INTNode> ;
generates
INTNode v = new INTNode(LT(1));
but we need to instead generate:
AST v = (AST)astFactory.create(LT(1),"INTNode");
where the create(...) method is new and specifies the type to
create. This will use newInstance() instead of "new" by default.
4. If you define ID<AST=T> in tokens section then all code in grammar
"id:ID" should
define labels as "T id" not "AST id" nor labelASTType id.
Make sense to folks? I think this is the "type table in the ast
factory" problem that Ric fixed in the C++ output.
Ter
PS Michael let's talk about C# integration.
--
Co-founder, http://www.jguru.com
Creator, ANTLR Parser Generator: http://www.antlr.org
Lecturer in Comp. Sci., University of San Francisco
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list