All pastes #414747 Raw Edit

Someone

public text v1 · immutable
#414747 ·published 2007-03-29 07:38 UTC
rendered paste body
fun transExp (venv,tenv) =
   let fun trexp (A.NilExp) = E.NIL
         | trexp (A.IntExp i) = E.INT
         | trexp (A.StringExp(s,pos)) = E.STRING
       (*  | trexp (A.VarExp var) = trvar (var)*)

         | trexp (A.OpExp{left,oper=A.PlusOp,right,pos}) =
                  let val tyleft = trexp(left)
                     val tyright = trexp(right)
                     in case tyleft of E.INT => E.INT
                                | _ => ((error pos "INT required"); E.ERROR);
                     case tyright of E.INT => E.INT
                                | _ => ((error pos "INT required"); E.ERROR);
                     E.INT
                  end 
         | trexp (A.OpExp{left,oper=A.MinusOp,right,pos}) =
                  let val tyleft = trexp(left)
                     val tyright = trexp(right)
                     in case tyleft of E.INT => E.INT
                                | _ => ((error pos "INT required"); E.ERROR);
                     case tyright of E.INT => E.INT
                                | _ => ((error pos "INT required"); E.ERROR);
                     E.INT
                  end 
         | trexp (A.OpExp{left,oper=A.TimesOp,right,pos}) =
                  let val tyleft = trexp(left)
                     val tyright = trexp(right)
                     in case tyleft of E.INT => E.INT
                                | _ => ((error pos "INT required"); E.ERROR);
                     case tyright of E.INT => E.INT
                                | _ => ((error pos "INT required"); E.ERROR);
                     E.INT
                  end 
         | trexp (A.OpExp{left,oper=A.DivideOp,right,pos}) =
                  let val tyleft = trexp(left)
                     val tyright = trexp(right)
                     in case tyleft of E.INT => E.INT
                                | _ => ((error pos "INT required"); E.ERROR);
                     case tyright of E.INT => E.INT
                                | _ => ((error pos "INT required"); E.ERROR);
                     E.INT
                  end
         
         | trexp (A.OpExp{left,oper=A.LtOp,right,pos}) =
                  let val tyleft = trexp(left)
                     val tyright = trexp(right)
                     in if tyeq(tyleft,tyright) = true then
                           (case tyleft of E.INT => E.INT
                                         | E.STRING => E.INT
                                         | _ => ((err pos "INT or STRING required"); E.ERROR);)
                     else  E.ERROR
                  end
        in trexp
   end