public static Cons foreachToPrefixForeachTree(Cons foreachtree) {
    { Cons generatorsclause = null;
      Stella_Object filterclause = null;
      Cons doclause = null;
      Stella_Object collectclause = null;
      Stella_Object intoclause = null;
      Cons residue = ((Cons)(foreachtree.rest));
      Cons otree = null;

      { Object [] caller_MV_returnarray = new Object[1];

        generatorsclause = Cons.extractGeneratorsClause(residue, caller_MV_returnarray);
        residue = ((Cons)(caller_MV_returnarray[0]));
      }
      if (generatorsclause == null) {
        return (Cons.list$(Cons.cons(Stella.SYM_STELLA_PREFIX_FOREACH, Cons.cons(Cons.list$(Cons.cons(Stella.SYM_STELLA_IN, Cons.cons(Stella.SYM_STELLA_X, Cons.cons(Stella.SYM_STELLA_NIL, Cons.cons(Stella.NIL, Stella.NIL))))), Cons.cons(Cons.list$(Cons.cons(Stella.SYM_STELLA_DO, Cons.cons(Stella_Object.walkDontCallMeTree(otree, Stella.SGT_STELLA_VOID, new Object[1]), Cons.cons(Stella.NIL, Stella.NIL)))), Cons.cons(Stella.NIL, Stella.NIL))))));
      }
      { Object [] caller_MV_returnarray = new Object[1];

        filterclause = Symbol.extractOptionAndResidue(Stella.SYM_STELLA_WHERE, residue, caller_MV_returnarray);
        residue = ((Cons)(caller_MV_returnarray[0]));
      }
      if (filterclause != null) {
        filterclause = Cons.list$(Cons.cons(Stella.SYM_STELLA_WHERE, Cons.cons(filterclause, Cons.cons(Stella.NIL, Stella.NIL))));
      }
      { Object [] caller_MV_returnarray = new Object[1];

        doclause = Cons.extractDoClause(residue, caller_MV_returnarray);
        residue = ((Cons)(caller_MV_returnarray[0]));
      }
      { Object [] caller_MV_returnarray = new Object[1];

        collectclause = Symbol.extractOptionAndResidue(Stella.SYM_STELLA_COLLECT, residue, caller_MV_returnarray);
        residue = ((Cons)(caller_MV_returnarray[0]));
      }
      { Object [] caller_MV_returnarray = new Object[1];

        intoclause = Symbol.extractOptionAndResidue(Stella.SYM_STELLA_INTO, residue, caller_MV_returnarray);
        residue = ((Cons)(caller_MV_returnarray[0]));
      }
      if ((collectclause != null) ||
          (intoclause != null)) {
        collectclause = Cons.list$(Cons.cons(Stella.SYM_STELLA_COLLECT_INTO, Cons.cons(collectclause, Cons.cons(Cons.cons(intoclause, Stella.NIL), Stella.NIL))));
      }
      otree = Cons.list$(Cons.cons(Stella.SYM_STELLA_PREFIX_FOREACH, Cons.cons(generatorsclause, Cons.cons((((filterclause != null) ? Cons.cons(filterclause, Stella.NIL) : Stella.NIL)).concatenate((((doclause != null) ? Cons.cons(doclause, Stella.NIL) : Stella.NIL)).concatenate((((collectclause != null) ? Cons.cons(collectclause, Stella.NIL) : Stella.NIL)).concatenate(Stella.NIL, Stella.NIL), Stella.NIL), Stella.NIL), Stella.NIL))));
      if (((collectclause != null) &&
          (intoclause == null)) ||
          ((intoclause != null) &&
           (collectclause == null))) {
        { Object old$PrintreadablyP$000 = Stella.$PRINTREADABLYp$.get();

          try {
            Native.setBooleanSpecial(Stella.$PRINTREADABLYp$, true);
            Stella.signalTranslationError();
            if (!(Stella.suppressWarningsP())) {
              Stella.printErrorContext(">> ERROR: ", Stella.STANDARD_ERROR);
              {
                Stella.STANDARD_ERROR.nativeStream.println();
                Stella.STANDARD_ERROR.nativeStream.println(" Missing COLLECT or INTO clause in.");
              }
;
            }

          } finally {
            Stella.$PRINTREADABLYp$.set(old$PrintreadablyP$000);
          }
        }
        return (Cons.list$(Cons.cons(Stella.SYM_STELLA_PREFIX_FOREACH, Cons.cons(Cons.list$(Cons.cons(Stella.SYM_STELLA_IN, Cons.cons(Stella.SYM_STELLA_X, Cons.cons(Stella.SYM_STELLA_NIL, Cons.cons(Stella.NIL, Stella.NIL))))), Cons.cons(Cons.list$(Cons.cons(Stella.SYM_STELLA_DO, Cons.cons(Stella_Object.walkDontCallMeTree(otree, Stella.SGT_STELLA_VOID, new Object[1]), Cons.cons(Stella.NIL, Stella.NIL)))), Cons.cons(Stella.NIL, Stella.NIL))))));
      }
      if (!(residue == Stella.NIL)) {
        { Object old$PrintreadablyP$001 = Stella.$PRINTREADABLYp$.get();

          try {
            Native.setBooleanSpecial(Stella.$PRINTREADABLYp$, true);
            Stella.signalTranslationError();
            if (!(Stella.suppressWarningsP())) {
              Stella.printErrorContext(">> ERROR: ", Stella.STANDARD_ERROR);
              {
                Stella.STANDARD_ERROR.nativeStream.println();
                Stella.STANDARD_ERROR.nativeStream.println(" Extra expressions at the end of foreach statement: `" + Stella_Object.deUglifyParseTree(residue) + "'.");
              }
;
            }

          } finally {
            Stella.$PRINTREADABLYp$.set(old$PrintreadablyP$001);
          }
        }
        return (Cons.list$(Cons.cons(Stella.SYM_STELLA_PREFIX_FOREACH, Cons.cons(Cons.list$(Cons.cons(Stella.SYM_STELLA_IN, Cons.cons(Stella.SYM_STELLA_X, Cons.cons(Stella.SYM_STELLA_NIL, Cons.cons(Stella.NIL, Stella.NIL))))), Cons.cons(Cons.list$(Cons.cons(Stella.SYM_STELLA_DO, Cons.cons(Stella_Object.walkDontCallMeTree(otree, Stella.SGT_STELLA_VOID, new Object[1]), Cons.cons(Stella.NIL, Stella.NIL)))), Cons.cons(Stella.NIL, Stella.NIL))))));
      }
      return (otree);
    }
  }