[antlr-interest] There is any documetation I can check; Fwd: How should I extend CommonTreeNodeStream?

Marwan Ajraoui marwan.alephn at gmail.com
Thu Aug 13 16:33:45 PDT 2009


I did find how to implement it;

1. changed my main class setting a walker myAdator

				 // Create a tree Walker attached to the nodes stream
				 BTLSem walker = new BTLSem(nodes);
				 //setting the adapter to use
				 walker.setTreeAdaptor(adaptor);

2. overrides public Tree dupNode() in MyAdaptor


3.  overrides public Tree dupNode() in MyNodeTree since is called by
the one is overriden in the point 2

Hope that will save little time, to others new bites like me, that get
lost with so many options of use of this framework and considerably
poor documentation in proportion. That's the common problem of
opensource projects :-(

Cheers,




2009/8/13 Marwan Ajraoui <marwan.alephn at gmail.com>:
> ---------- Forwarded message ----------
> From: Marwan Ajraoui <marwan.alephn at gmail.com>
> Date: 2009/8/13
> Subject: How should I extend CommonTreeNodeStream? Do I need to change
> my adaptor or something else?
> To: antlr-interest at antlr.org
>
>
> Hi there;
>
> I did define a customized node, extending a commonTree, defined an
> adaptor extending a  CommonTreeAdaptor, for my semantic analysis.
>
> I did extend as well CommonErrorNode;
>
> And now myAdaptor look like:
>
> public class BTLTreeAdaptor extends CommonTreeAdaptor{
>        @Override
>        public Object create(Token payload) {
>                return new BTLNodeTree(payload);
>        }
>        @Override
>        public Object errorNode(TokenStream input, Token start, Token stop,
> RecognitionException e) {
>                return new BTLErrorNode(input, start, stop, e);
>        }
>
> Now I supose, that I have to extend CommonTreeNodeStream because I'm
> getting a classCastExcpetion, I didn't find any information in the
> book:
> The Definitive ANTLR Reference, about how to deal with that. I'm using
> ANTLR v3.1.
>
> How should I extend CommonTreeNodeStream? Do I need to change my
> adaptor or something else? My customized node tree has just few
> attributes, to allow the walker to analyze the semantic of the
> language I'm defining.
>
> My customized node tree look like:
>
> public class BTLNodeTree extends CommonTree {
>
>        public Identificador identificador;
>        public SymbolConst symbolConst;
>        public String expType = "";
>        public String expSecType = "";
>
>        public BTLNodeTree(Token t)
>        {
>                 super(t);
>        }
> }
>
>
> Thx in advance for your help,
>
> Cheers
>
> --
> Marouane
>
>
>
> --
> Marouane
>



-- 
Marouane


More information about the antlr-interest mailing list