public static Stella_Object buildTopLevelTerm(Stella_Object tree) {
    { Stella_Object term = null;

      { Object old$Logicvariabletable$000 = Logic.$LOGICVARIABLETABLE$.get();
        Object old$Variableidcounter$000 = Logic.$VARIABLEIDCOUNTER$.get();
        Object old$Termunderconstruction$000 = Logic.$TERMUNDERCONSTRUCTION$.get();

        try {
          Native.setSpecial(Logic.$LOGICVARIABLETABLE$, Stella.NIL);
          Native.setIntSpecial(Logic.$VARIABLEIDCOUNTER$, 0);
          Native.setSpecial(Logic.$TERMUNDERCONSTRUCTION$, tree);
          if (Stella_Object.safePrimaryType(tree) == Logic.SGT_STELLA_CONS) {
            { Cons tree000 = ((Cons)(tree));

              if (Stella.getQuotedTree("((FORALL EXISTS IMPLIES AND OR NOT) \"/LOGIC\")", "/LOGIC").memberP(tree000.value)) {
                {
                  Stella.STANDARD_WARNING.nativeStream.println("Warning: Sentence where term expected: `" + tree000 + "'");
                  Stella.STANDARD_WARNING.nativeStream.println();
                }
;
                return (null);
              }
            }
          }
          else {
          }
          term = Logic.evaluateTerm(tree);

        } finally {
          Logic.$TERMUNDERCONSTRUCTION$.set(old$Termunderconstruction$000);
          Logic.$VARIABLEIDCOUNTER$.set(old$Variableidcounter$000);
          Logic.$LOGICVARIABLETABLE$.set(old$Logicvariabletable$000);
        }
      }
      return (term);
    }
  }