[antlr-interest] Changes in ASTFactory breaks custom AST classes

Marco Hunsicker development at hunsicker.de
Sun Dec 8 05:44:46 PST 2002

Hi all,

I've just updated to the current ANTLR distro (2.7.2a6-20021130) and
noticed that my dereived ASTFactory did not work as expected anymore
(I only use the Java stuff). I took a look at antlr.ASTFactory.java
and realized that the dup(AST) method changed (of course, the whole
class was expanded, but this is the one change that has bitten me).

2.7.2a2 looked like
public AST dup(AST t) {
    return create(t); // if t==null, create returns null}

2.7.2a6 does
public AST dup(AST t) {
    if ( t==null ) {
        return null;
    // don't just call
    AST dup_t = create(t.getClass());
    dup_t.initialize(t.getType(), t.getText());
                  // ^
                  // why not use initialize(t) ???
    return dup_t;

The problem (at least for me) lies in the fact that the duplicated
node gets only initialized with the type and text! All other
information stored in the original node is lost. I now simply
override dup(AST) too, changing it back to the old behavior (I only
use homogenous trees) but I'd rather expect dup(AST) to initialize the
duplicated node via dup_t.initialize(t) or am I missing something here?

Another minor thing I've noticed is that the new "classHeaderPrefix"
option (cool!) has been only implemented for lexers. I hope this is
not intentional?

BTW, I don't like constant interfaces and added a new option
"useTokenPrefix=true|false" to avoid this technique. If specified, the
lexer/parser classes don't implement a constant interface, but rather
use tokens prefixed with the xxxTokenClass name (e.g. IDENT becomes
JavaTokenTypes.IDENT). All token constants are defined in an immutable
class. Maybe these (simple) changes could be merged into the public
code base? (I could send you the patched antlr.Grammar.java and
antlr.JavaCodeGenerator.java, if appreciated).

Anyway, many thanks for creating such an exceptional piece of
software. Love it!

Best regards,


Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 

More information about the antlr-interest mailing list