Example usage for org.antlr.v4.runtime.misc IntegerStack pop

List of usage examples for org.antlr.v4.runtime.misc IntegerStack pop

Introduction

In this page you can find the example usage for org.antlr.v4.runtime.misc IntegerStack pop.

Prototype

public final int pop() 

Source Link

Usage

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;
    }/*w w  w  .jav a  2 s .c om*/

    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;
}