(defun inf-to-pre (ae) (cond ((atom ae) ae) (T (inf-aux ae nil nil)))) (defun inf-aux (ae operators operands) (inf-iter (cdr ae) operators (cons (inf-to-pre (car ae)) operands))) (defun inf-iter (ae operators operands) (cond ((and (null ae) (null operators)) (car operands)) ((and (not (null ae)) (or (null operators) (> (weight (car ae)) (weight (car operators))))) (inf-aux (cdr ae) (cons (car ae) operators) operands)) (T (inf-iter ae (cdr operators) (cons (list (opcode (car operators)) (cadr operands) (car operands)) (cddr operands)))))) (defun weight (operator) (cond ((equal operator '=) 0) ((equal operator '+) 1) ((equal operator '-) 1) ((equal operator '*) 2) ((equal operator '/) 2) ((equal operator '\\) 2) ((equal operator '^) 3) (T (print `(,operator not an operator)) 4))) (defun opcode (operator) (cond ((equal operator '=) 'setq) ((equal operator '+) '+) ((equal operator '-) '-) ((equal operator '*) '*) ((equal operator '/) '/) ((equal operator '\\) 'rem) ((equal operator '^) 'expt) (T (print `(,operator not an operator)) operator)))