List of usage examples for org.antlr.v4.runtime.misc IntegerStack push
public final void push(int value)
From source file:com.xiaomi.linden.bql.BQLCompiler.java
License:Apache License
private static TerminalNode getStartNode(ParseTree tree) { if (tree instanceof TerminalNode) { return (TerminalNode) tree; }//from www . j a v a 2s. co m 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; }