Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
0
 internal void AddContent(GrammarTree tree)
 {
     if (!string.IsNullOrEmpty(name))
     {
         GrammarTreeNode node = new GrammarTreeNode();
         node.propName = name;
         tree.propertices.Add(node);
     }
 }
Exemplo n.º 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);
 }
Exemplo n.º 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);
        }
Exemplo n.º 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;
            //}
        }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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);
        }
Exemplo n.º 9
0
 internal virtual bool Match(List <Token> tokens, ref int n, GrammarTree parentTree)
 {
     throw new Exception();
 }
Exemplo n.º 10
0
 internal override bool Match(List <Token> tokens, ref int n, GrammarTree parentTree)
 {
     return(true);
 }