[antlr-interest] Parsing any tree using tree grammer?

Kamal Verma kverma at yahoo.com
Fri Jul 13 08:36:40 PDT 2007


Thanks for the reply Antlr.Runtime.Tree.ITree is what I meant. Interface is as follows,

public interface ITree
    {
        int CharPositionInLine { get; }
        int ChildCount { get; }
        bool IsNil { get; }
        int Line { get; }
        string Text { get; }
        int TokenStartIndex { get; set; }
        int TokenStopIndex { get; set; }
        int Type { get; }

        void AddChild(ITree t);
        ITree DupNode();
        ITree DupTree();
        ITree GetChild(int i);
        string ToString();
        string ToStringTree();
    }

For read only purposes I think we'll need only few items (IsNil, ChildCount, GetChild are things that convert tree into tree stream). I was wondering if we can a cleaner and smaller read-only interface that excludes various things that meant to mutate the node. TreeAdaptor is even bigger interface;

public interface ITreeAdaptor
    {
        void AddChild(object t, object child);
        object BecomeRoot(IToken newRoot, object oldRoot);
        object BecomeRoot(object newRoot, object oldRoot);
        object Create(IToken payload);
        object Create(int tokenType, IToken fromToken);
        object Create(int tokenType, string text);
        object Create(int tokenType, IToken fromToken, string text);
        object DupNode(object treeNode);
        object DupTree(object tree);
        object GetChild(object t, int i);
        int GetChildCount(object t);
        object GetNilNode();
        string GetNodeText(object t);
        int GetNodeType(object t);
        IToken GetToken(object treeNode);
        int GetTokenStartIndex(object t);
        int GetTokenStopIndex(object t);
        int GetUniqueID(object node);
        bool IsNil(object tree);
        object RulePostProcessing(object root);
        void SetNodeText(object t, string text);
        void SetNodeType(object t, int type);
        void SetTokenBoundaries(object t, IToken startToken, IToken stopToken);
    }

Technically, either of them can help achieve the tree grammar parsing; I was wondering if we can little more light weight interfaces to work with. Or these can be refactored to simpler ones; I think this is more for the architect of antlr framework to decide.

Meanwhile I will look into implementation of above and use those with tree grammar.

-Kamal


----- Original Message ----
From: Randall R Schulz <rschulz at sonic.net>
To: antlr-interest at antlr.org
Sent: Friday, July 13, 2007 11:20:39 AM
Subject: Re: [antlr-interest] Parsing any tree using tree grammer?

On Friday 13 July 2007 07:23, Kamal Verma wrote:
> Hi All,
>
> Does anybody have thoughts parsing any tree of type "ITree" using
> tree grammar. Can this be done ? I looked at ITree interface,

What is ITree? org.antlr.Tree is the interface that must be implemented 
if a tree is to be parseable in an ANTLR tree parser, right?


> I was wondering is there any more simpler interface I can use to
> create parseable tree??

Well, Tree is not really an exceptionally complex interface to 
implement. If you already have a class or classes that are essentially 
tree-structureed, then you should write an adaptor class that makes 
that tree structure appear to the ANTLR tree parser like its Tree 
interface.

I don't think there's a way to short-cut that task.


> Something like,
> 
> interface ITree
> {
>       int ChildCount;
>      ITree getChild(int i);
> }
>
> Any thoughts ? comments ?
>
> -Kamal


Randall Schulz







       
____________________________________________________________________________________
Be a better Heartthrob. Get better relationship answers from someone who knows. Yahoo! Answers - Check it out. 
http://answers.yahoo.com/dir/?link=list&sid=396545433
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070713/ff667624/attachment.html 


More information about the antlr-interest mailing list