本文整理匯總了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("");
}
}
示例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();
}
}
}
示例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;
}
示例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;
}
示例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:
//.........這裏部分代碼省略.........
示例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;
}
示例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;
}
示例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;
}
示例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;
}