public static boolean hasPotentialInfiniteLoop(Node<?> node) {
        for (;;) {
            if (node instanceof RepeatNode && ((RepeatNode) node).sibling.isNullable())
                return true;

            if (node instanceof GrammarNode)
                return false; // Grammars have already been checked

            if (node instanceof UnaryNode) {
                node = ((UnaryNode) node).sibling;
            } else if (node instanceof BinaryNode) {
                BinaryNode n = (BinaryNode) node;
                if (hasPotentialInfiniteLoop(n.firstSibling))
                    return true;

                node = n.secondSibling;
            } else {
                return false;
            }
        }
    }