private static Statement getNextStatement(Statement stat) {
    Statement parent = stat.getParent();
    switch (parent.type) {
      case ROOT -> {
        return ((RootStatement)parent).getDummyExit();
      }
      case DO -> {
        return parent;
      }
      case SEQUENCE -> {
        SequenceStatement sequence = (SequenceStatement)parent;
        if (sequence.getStats().getLast() != stat) {
          for (int i = sequence.getStats().size() - 1; i >= 0; i--) {
            if (sequence.getStats().get(i) == stat) {
              return sequence.getStats().get(i + 1);
            }
          }
        }
      }
    }

    return getNextStatement(parent);
  }
private static Statement getNextStatement(Statement stat)