Contents    Page-10    Prev    Next    Page+10    Index   

Basic Expression Algorithm

The basic algorithm for expressions is easy: postorder.


(defun genarith (x)
  (if (atom x)              ; if leaf,
      (genload x (getreg))  ;   load
      (genop (op x)         ; else op
             (genarith (lhs x))
             (genarith (rhs x))) ) )


>(genarith '(* (+ a b) 3))
   LOAD  A,R1
   LOAD  B,R2
   ADD   R1,R2
   LOAD  3,R3
   MUL   R2,R3
R3