Advertisement
Guest User

Untitled

a guest
Mar 25th, 2015
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.81 KB | None | 0 0
  1. let pushNum i =
  2.     match i with
  3.     | IntVal x -> "ldc.i4.s " + string x
  4.     | _        -> failwith "Syntax error"    
  5.    
  6.  
  7. let rec compile expr =
  8.     match expr with
  9.     | ConstInt i                  -> pushNum (IntVal i)
  10.     | PrimOp ("+", lOper, rOper)  -> evalNumericExpr (+) lOper rOper
  11.     //| PrimOp ("-", lOper, rOper)  -> evalNumericExpr (-) lOper rOper
  12.     //| PrimOp ("*", lOper, rOper)  -> evalNumericExpr (*) lOper rOper
  13.     //| PrimOp ("/", lOper, rOper)  -> evalNumericExpr (/) lOper rOper
  14.     //| PrimOp ("%", lOper, rOper)  -> evalNumericExpr (%) lOper rOper
  15.     | _                 -> failwith "Syntax error"    
  16.  
  17. and evalNumericExpr op lOper rOper =
  18.     let left = compile lOper
  19.     let right = compile rOper
  20.     match (op) with
  21.     | (+) ->  "ADD"
  22.     | _   -> failwith "Syntax error"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement