[antlr-interest] How do you create an adaptor in C# that allows you to extend CommonTree?

Rob Dougan rob_dougan at sympatico.ca
Mon Aug 10 11:25:44 PDT 2009


I would like to add some stuff to the CommonTree node and hook it up using an adaptor,

I am not a java programmer and actually i am pretty new to ANTLR and C# as well ...

It just amounts to translating the following java snippet (thanks Terrence) into C#

 

java:

// An adaptor that tells ANTLR to build custom AST node (myAST)

public static TreeAdaptor anAdaptor = new CommonTreeAdaptor() {

    public Object create(Token token) {

        return new myAST(token);

    }

    public Object dupNode(Object obj) {

        if ( obj == null ) return null;

        return create(((myAST)obj).token);

    }

    public Object errorNode(TokenStream input,Token start,Token stop,RecognitionException ex) {

    return new myErrorNode(input,start,stop,ex);

    }

};

 

c#:

?

i am sure i will get this eventually but this must be a pretty common thing to do...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090810/4995c71a/attachment.html 


More information about the antlr-interest mailing list