Example #1
0
 public TreePatternParser( TreePatternLexer tokenizer, TreeWizard wizard, ITreeAdaptor adaptor )
 {
     this.tokenizer = tokenizer;
     this.wizard = wizard;
     this.adaptor = adaptor;
     ttype = tokenizer.NextToken(); // kickstart
 }
Example #2
0
 public TreePatternParser(TreePatternLexer tokenizer, TreeWizard wizard, ITreeAdaptor adaptor)
 {
     this.tokenizer = tokenizer;
     this.wizard    = wizard;
     this.adaptor   = adaptor;
     this.ttype     = tokenizer.NextToken();
 }
        public virtual object ParseTree()
        {
            if (ttype != TreePatternLexer.Begin)
            {
                throw new InvalidOperationException("No beginning.");
            }

            ttype = tokenizer.NextToken();
            object root = ParseNode();

            if (root == null)
            {
                return(null);
            }
            while (ttype == TreePatternLexer.Begin ||
                   ttype == TreePatternLexer.Id ||
                   ttype == TreePatternLexer.Percent ||
                   ttype == TreePatternLexer.Dot)
            {
                if (ttype == TreePatternLexer.Begin)
                {
                    object subtree = ParseTree();
                    adaptor.AddChild(root, subtree);
                }
                else
                {
                    object child = ParseNode();
                    if (child == null)
                    {
                        return(null);
                    }
                    adaptor.AddChild(root, child);
                }
            }

            if (ttype != TreePatternLexer.End)
            {
                throw new InvalidOperationException("No end.");
            }

            ttype = tokenizer.NextToken();
            return(root);
        }
Example #4
0
        public object ParseTree()
        {
            if (ttype != TreePatternLexer.BEGIN)
            {
                Console.Out.WriteLine("no BEGIN");
                return(null);
            }
            ttype = tokenizer.NextToken();
            object root = ParseNode();

            if (root == null)
            {
                return(null);
            }
            while (ttype == TreePatternLexer.BEGIN ||
                   ttype == TreePatternLexer.ID ||
                   ttype == TreePatternLexer.PERCENT ||
                   ttype == TreePatternLexer.DOT)
            {
                if (ttype == TreePatternLexer.BEGIN)
                {
                    object subtree = ParseTree();
                    adaptor.AddChild(root, subtree);
                }
                else
                {
                    object child = ParseNode();
                    if (child == null)
                    {
                        return(null);
                    }
                    adaptor.AddChild(root, child);
                }
            }
            if (ttype != TreePatternLexer.END)
            {
                Console.Out.WriteLine("no END");
                return(null);
            }
            ttype = tokenizer.NextToken();
            return(root);
        }