[antlr-interest] (no subject)

Florian Friedemann cerbff at cs.tu-berlin.de
Tue Oct 7 05:53:53 PDT 2008


Hi,
I'm currently working on a parser generating an AST.
Into that AST I want to put information that hasn't been parsed but generated during the process of parsing
(one example would be the Integer-typed index of a parsed variable within a scope).
So I wrote a function creating a CommonTree.

When I put this Tree into a rewrite rule I now get the warning:
   [org.antlr.works.debugger.tree.DBASTModel - event 15416] Warning: [addChild] Child node 900 not found, ignoring.
And the generated AST doesn't contain the tree generated by that function.

The function looks like this (implemented according to chapter 7 on tree construction of the reference)

CommonTree getTree() {
 	TreeAdaptor adaptor = new CommonTreeAdaptor();
 	CommonTree varRefList = (CommonTree)adaptor.nil();

 	varRefList.addChild((CommonTree)adaptor.create(INT, frameCnt.toString()));
 	varRefList.addChild((CommonTree)adaptor.create(INT, varId.toString()));

 	return varRefList;
}
were frameCnt and varId are member variables of type Integer

the rule were it is used looks similar to this:

identifier
scope {
 	CommonTree varRefTree;
}
    :  (ID {$identifier::varRefTree = getVarId($ID.getText()).getTree();}
 	-> ^(IDENTIFIER ^(VAR_REF ID {$identifier::varRefTree}))
 	)

parser options are:
backtrack=true;
memoize=true;
output=AST;
ASTLabelType=CommonTree;

Versions:
ANTLRWorks: 1.2
ANTLR: 3.1

So my questions are:
Is this approach (building the tree "by hand") flawed in general?
If not, what can I do to avoid those warnings and add the tree to the generated AST.
If it is flawed, is there any other way I can add information that was generated during parsing to the AST?

Many thanks in advance



More information about the antlr-interest mailing list