Example #1
0
        public GrammarTree Generate(Config config, string content)
        {
            mConfig = config;

            if (!mConfig.Valid)
            {
                return(null);
            }

            DateTime t0 = DateTime.Now;

            mTokens = mScanner.Scan(this, content);

            mTree = GenerateTree(mConfig.grammar.root);

            ErrorReport();

            TimeSpan span = new TimeSpan(DateTime.Now.Ticks - t0.Ticks);

            if (mConfig.msgHaneler != null)
            {
                mConfig.msgHaneler(string.Format("Time:{0:00}:{1:00}:{2:00}:{3:00}", span.Hours, span.Minutes, span.Seconds, span.Milliseconds));
            }

            return(mTree);
        }
Example #2
0
        internal void AddContent(GrammarTree tree, List <Token> tokens, int n)
        {
            PropertyTreeNode node = new PropertyTreeNode();

            node.propName = name;
            node.content  = tokens[n].Word;
            tree.propertices.Add(node);
        }
Example #3
0
 internal void AddContent(GrammarTree tree)
 {
     if (!string.IsNullOrEmpty(name))
     {
         GrammarTreeNode node = new GrammarTreeNode();
         node.propName = name;
         tree.propertices.Add(node);
     }
 }
Example #4
0
 internal override bool Match(List <Token> tokens, ref int n, GrammarTree parentTree)
 {
     foreach (var child in children)
     {
         int offset = n;
         if (!child.Match(tokens, ref offset, parentTree))
         {
             n = offset;
             return(true);
         }
     }
     return(false);
 }
Example #5
0
        GrammarTree GenerateTree(Production p)
        {
            GrammarTree tree = new GrammarTree();

            tree.propName = p.ToString();
            int offset = 0;

            if (p.Match(mTokens, ref offset, tree))
            {
                mTree = tree;
            }

            return(mTree);
        }
Example #6
0
        internal override bool Match(List <Token> tokens, ref int n, GrammarTree parentTree)
        {
            return(false);
            //throw new Exception();

            //if (tokens[n].Tag == tokenid)
            //{
            //    n++;
            //    return true;
            //}
            //else
            //{
            //    return false;
            //}
        }
Example #7
0
 internal override bool Match(List <Token> tokens, ref int n, GrammarTree parentTree)
 {
     if (tokens[n] is EofToken)
     {
         return(true);
     }
     if (tokens[n].Word == content)
     {
         n++;
         return(true);
     }
     else
     {
         return(false);
     }
 }
Example #8
0
        internal override bool Match(List <Token> tokens, ref int n, GrammarTree parentTree)
        {
            if (node)
            {
                node.AddContent(parentTree);
            }
            int offset = n;

            foreach (var child in children)
            {
                if (!child.Match(tokens, ref offset, parentTree))
                {
                    parentTree.Clear();
                    return(false);
                }
            }
            n = offset;
            return(true);
        }
Example #9
0
 internal virtual bool Match(List <Token> tokens, ref int n, GrammarTree parentTree)
 {
     throw new Exception();
 }
Example #10
0
 internal override bool Match(List <Token> tokens, ref int n, GrammarTree parentTree)
 {
     return(true);
 }