本文整理汇总了C#中IParseTreeListener.VisitErrorNode方法的典型用法代码示例。如果您正苦于以下问题:C# IParseTreeListener.VisitErrorNode方法的具体用法?C# IParseTreeListener.VisitErrorNode怎么用?C# IParseTreeListener.VisitErrorNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IParseTreeListener
的用法示例。
在下文中一共展示了IParseTreeListener.VisitErrorNode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Walk
public virtual void Walk(IParseTreeListener listener, IParseTree t)
{
if (t is IErrorNode)
{
listener.VisitErrorNode((IErrorNode)t);
return;
}
else
{
if (t is ITerminalNode)
{
listener.VisitTerminal((ITerminalNode)t);
return;
}
}
IRuleNode r = (IRuleNode)t;
EnterRule(listener, r);
int n = r.ChildCount;
for (int i = 0; i < n; i++)
{
Walk(listener, r.GetChild(i));
}
ExitRule(listener, r);
}
示例2: Walk
public virtual void Walk(IParseTreeListener listener, IParseTree t)
{
Stack<IParseTree> nodeStack = new Stack<IParseTree>();
Stack<int> indexStack = new Stack<int>();
IParseTree currentNode = t;
int currentIndex = 0;
while (currentNode != null)
{
// pre-order visit
if (currentNode is IErrorNode)
{
listener.VisitErrorNode((IErrorNode)currentNode);
}
else
{
if (currentNode is ITerminalNode)
{
listener.VisitTerminal((ITerminalNode)currentNode);
}
else
{
IRuleNode r = (IRuleNode)currentNode;
EnterRule(listener, r);
}
}
// Move down to first child, if exists
if (currentNode.ChildCount > 0)
{
nodeStack.Push(currentNode);
indexStack.Push(currentIndex);
currentIndex = 0;
currentNode = currentNode.GetChild(0);
continue;
}
do
{
// No child nodes, so walk tree
// post-order visit
if (currentNode is IRuleNode)
{
ExitRule(listener, (IRuleNode)currentNode);
}
// No parent, so no siblings
if (nodeStack.Count == 0)
{
currentNode = null;
currentIndex = 0;
break;
}
// Move to next sibling if possible
currentNode = nodeStack.Peek().GetChild(++currentIndex);
if (currentNode != null)
{
break;
}
// No next sibling, so move up
currentNode = nodeStack.Pop();
currentIndex = indexStack.Pop();
}
while (currentNode != null);
}
}