public TreePatternParser(TreePatternLexer tokenizer, TreeWizard wizard, ITreeAdaptor adaptor) { this.tokenizer = tokenizer; this.wizard = wizard; this.adaptor = adaptor; ttype = tokenizer.NextToken(); // kickstart }
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); }