当前位置: 首页>>代码示例>>C#>>正文


C# AST.getFirstChild方法代码示例

本文整理汇总了C#中AST.getFirstChild方法的典型用法代码示例。如果您正苦于以下问题:C# AST.getFirstChild方法的具体用法?C# AST.getFirstChild怎么用?C# AST.getFirstChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AST的用法示例。


在下文中一共展示了AST.getFirstChild方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: visit

		public void visit(AST node) 
		{
			// Flatten this level of the tree if it has no children
			bool flatten = /*true*/ false;
			AST node2;
			for (node2 = node; node2 != null; node2 = node2.getNextSibling()) 
			{
				if (node2.getFirstChild() != null) 
				{
					flatten = false;
					break;
				}
			}

			for (node2 = node; node2 != null; node2 = node2.getNextSibling()) 
			{
				if (!flatten || node2 == node) 
				{
					tabs();
				}
				if (node2.getText() == null) 
				{
					Console.Out.Write("nil");
				}
				else 
				{
					Console.Out.Write(node2.getText());
				}

				Console.Out.Write(" [" + node2.Type + "] ");

				if (flatten) 
				{
					Console.Out.Write(" ");
				}
				else 
				{
					Console.Out.WriteLine("");
				}

				if (node2.getFirstChild() != null) 
				{
					level++;
					visit(node2.getFirstChild());
					level--;
				}
			}

			if (flatten) 
			{
				Console.Out.WriteLine("");
			}
		}
开发者ID:alexed1,项目名称:dtrack,代码行数:53,代码来源:DumpASTVisitor.cs

示例2: DumpNode

        private static void DumpNode(AST rootNode, int level)
        {
            Trace.WriteLine(new string(' ', level) + rootNode.ToString());

            int numberOfChildren = rootNode.getNumberOfChildren();
            if (numberOfChildren > 0)
            {
                AST node = rootNode.getFirstChild();
                while (node != null)
                {
                    DumpNode(node, level + 2);
                    node = node.getNextSibling();
                }
            }
        }
开发者ID:serra,项目名称:spring-net,代码行数:15,代码来源:ExpressionEvaluatorTests.cs

示例3: GetChildren

 private List<AST> GetChildren(AST a)
 {
     List<AST> result = new List<AST>();
     AST current = a.getFirstChild();
     while (current != null)
     {
         result.Add(current);
         current = current.getNextSibling();
     }
     return result;
 }
开发者ID:jblomer,项目名称:GrGen.NET,代码行数:11,代码来源:ASTdapter.cs

示例4: dupTree

 /// <summary>
 /// Duplicate AST Node tree rooted at specified AST node. Ignore it's siblings.
 /// </summary>
 /// <param name="t">Root of AST Node tree.</param>
 /// <returns>Root node of new AST Node tree (or null if <c>t</c> is null).</returns>
 public virtual AST dupTree(AST t)
 {
     var result = dup(t); // make copy of root
     // copy all children of root.
     if (t != null)
     {
         result.setFirstChild(dupList(t.getFirstChild()));
     }
     return result;
 }
开发者ID:kog,项目名称:Solenoid-Expressions,代码行数:15,代码来源:ASTFactory.cs

示例5: InternalEvaluate

        /// <summary>
        /// Evaluates the tree, returns the resulting object.
        /// </summary>
        /// <param name="tree">AST tree to parse</param>
        /// <returns>Object depending on the type of expression</returns>
        object InternalEvaluate(AST tree, out Type resultType)
        {
            //AST returnedTree = null;
            object result = null;
            object a, b;

            try
            {

                if (tree == null)
                    tree = ASTNULL;

                switch (tree.Type)
                {
                    case ExpressionTokenTypes.GT:
                    case ExpressionTokenTypes.GTE:
                    case ExpressionTokenTypes.LTH:
                    case ExpressionTokenTypes.LTE:
                    case ExpressionTokenTypes.EQUAL:
                    case ExpressionTokenTypes.NOT_EQUAL:
                        {
                            AST tmpAST = tree;

                            tree = tree.getFirstChild();
                            Type aType;
                            a = InternalEvaluate(tree, out aType);

                            tree = tree.getNextSibling();
                            Type bType;
                            b = InternalEvaluate(tree, out bType);

                            tree = retTree_;
                            tree = tmpAST;
                            tree = tree.getNextSibling();

                            result = EvaluateEquality(aType, a, bType, b, tmpAST.getText());
                            resultType = typeof(bool);
                        }
                        break;

                    case ExpressionLexer.LITERAL_IN:
                    case ExpressionLexer.LITERAL_NOT:
                        {
                            AST tmpAST = tree; // NOT or IN

                            tree = tree.getFirstChild();
                            Type aType;
                            a = InternalEvaluate(tree, out aType);
                            ExpressionType leftType = GetExpressionType(a.GetType());

                            AST tmp = tree.getNextSibling();
                            ArrayList list = new ArrayList();
                            while (tmp != null)
                            {
                                Type oType;
                                object o = InternalEvaluate(tmp, out oType);
                                if (GetExpressionType(o.GetType()) != leftType)
                                {
                                    string msg = string.Format("Data type not match, '{0}'({1}) - '{2}'({3})",
                                        tmp.getText(), GetExpressionType(a.GetType()), tree.getText(), GetExpressionType(o.GetType()));
                                    throw new Exception(msg);
                                }
                                list.Add(o);
                                tmp = tmp.getNextSibling();
                            }

                            result = false;
                            //foreach(object o in list) {
                            //    if(a.Equals(o)) {
                            //        result = true;
                            //    }
                            //}
                            foreach (object o in list)
                            {
                                if (a.Equals(o) && tmpAST.Type == ExpressionLexer.LITERAL_IN)
                                    result = true;
                                else
                                {
                                    if (a.Equals(o) && tmpAST.Type == ExpressionLexer.LITERAL_NOT)
                                    {
                                        result = false;
                                        break;
                                    }
                                    else
                                    {
                                        if (!a.Equals(o) && tmpAST.Type == ExpressionLexer.LITERAL_NOT)
                                            result = true;
                                    }
                                }
                            }
                            resultType = typeof(bool);
                        }
                        break;

                    case ExpressionLexer.MULT:
//.........这里部分代码省略.........
开发者ID:sametyazak,项目名称:crosscheque,代码行数:101,代码来源:ExpressionTreeParser.cs

示例6: EqualsTreePartial

        /*Is 't' a subtree of the tree rooted at 'this'?  The siblings
        *  of 'this' are ignored.
        */
        public virtual bool EqualsTreePartial(AST sub)
        {
            // the empty tree is always a subset of any tree.
            if (sub == null)
            {
                return true;
            }

            // check roots first.
            if (!this.Equals(sub))
                return false;
            // if roots match, do full list partial match test on children.
            if (this.getFirstChild() != null)
            {
                if (!this.getFirstChild().EqualsListPartial(sub.getFirstChild()))
                    return false;
            }
            return true;
        }
开发者ID:alexed1,项目名称:dtrack,代码行数:22,代码来源:BaseAST.cs

示例7: EqualsTree

 /*Is tree rooted at 'this' equal to 't'?  The siblings
 *  of 'this' are ignored.
 */
 public virtual bool EqualsTree(AST t)
 {
     // check roots first.
     if (!this.Equals(t))
         return false;
     // if roots match, do full list match test on children.
     if (this.getFirstChild() != null)
     {
         if (!this.getFirstChild().EqualsList(t.getFirstChild()))
             return false;
     }
     else if (t.getFirstChild() != null)
     {
         return false;
     }
     return true;
 }
开发者ID:alexed1,项目名称:dtrack,代码行数:20,代码来源:BaseAST.cs

示例8: EqualsListPartial

        /*Is 'sub' a subtree of this list?
        *  The siblings of the root are NOT ignored.
        */
        public virtual bool EqualsListPartial(AST sub)
        {
            AST sibling;

            // the empty tree is always a subset of any tree.
            if (sub == null)
            {
                return true;
            }

            // Otherwise, start walking sibling lists.  First mismatch, return false.
            for (sibling = this; sibling != null && sub != null; sibling = sibling.getNextSibling(), sub = sub.getNextSibling())
            {
                // as a quick optimization, check roots first.
                if (!sibling.Equals(sub))
                    return false;
                // if roots match, do partial list match test on children.
                if (sibling.getFirstChild() != null)
                {
                    if (!sibling.getFirstChild().EqualsListPartial(sub.getFirstChild()))
                        return false;
                }
            }
            if (sibling == null && sub != null)
            {
                // nothing left to match in this tree, but subtree has more
                return false;
            }
            // either both are null or sibling has more, but subtree doesn't
            return true;
        }
开发者ID:alexed1,项目名称:dtrack,代码行数:34,代码来源:BaseAST.cs

示例9: EqualsList

        /*Is t an exact structural and equals() match of this tree.  The
        *  'this' reference is considered the start of a sibling list.
        */
        public virtual bool EqualsList(AST t)
        {
            AST sibling;

            // the empty tree is not a match of any non-null tree.
            if (t == null)
            {
                return false;
            }

            // Otherwise, start walking sibling lists.  First mismatch, return false.
            for (sibling = this; sibling != null && t != null; sibling = sibling.getNextSibling(), t = t.getNextSibling())
            {
                // as a quick optimization, check roots first.
                if (!sibling.Equals(t))
                {
                    return false;
                }
                // if roots match, do full list match test on children.
                if (sibling.getFirstChild() != null)
                {
                    if (!sibling.getFirstChild().EqualsList(t.getFirstChild()))
                    {
                        return false;
                    }
                }
                else if (t.getFirstChild() != null)
                {
                    return false;
                }
            }
            if (sibling == null && t == null)
            {
                return true;
            }
            // one sibling list has more than the other
            return false;
        }
开发者ID:alexed1,项目名称:dtrack,代码行数:41,代码来源:BaseAST.cs


注:本文中的AST.getFirstChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。