private static TerminalNode getStartNode(ParseTree tree) {
if (tree instanceof TerminalNode) {
return (TerminalNode) tree;
}
Deque<ParseTree> workList = new ArrayDeque<ParseTree>();
IntegerStack workIndexStack = new IntegerStack();
workList.push(tree);
workIndexStack.push(0);
while (!workList.isEmpty()) {
ParseTree currentTree = workList.peek();
int currentIndex = workIndexStack.peek();
if (currentIndex == currentTree.getChildCount()) {
workList.pop();
workIndexStack.pop();
continue;
}
// move work list to next child
workIndexStack.push(workIndexStack.pop() + 1);
// process the current child
ParseTree child = currentTree.getChild(currentIndex);
if (child instanceof TerminalNode) {
return (TerminalNode) child;
}
workList.push(child);
workIndexStack.push(0);
}
return null;
}
BQLCompiler.java 文件源码
java
阅读 25
收藏 0
点赞 0
评论 0
项目:linden
作者:
评论列表
文章目录