Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type Instruction = | ADD | SUB | MULT | DIV | SIN | COS | LOG | EXP | PUSH of float;;
- type stack = List<float>
- exception EmptyStack
- let intpInstr (s:stack) (i:Instruction) : stack =
- match (i, s) with
- | ADD, x :: y :: s' -> (x + y) :: s'
- | SUB, x :: y :: s' -> (x - y) :: s'
- | MULT, x :: y :: s' -> (x * y) :: s'
- | DIV, x :: y :: s' -> (x / y) :: s'
- | SIN, x :: s' -> sin (x) :: s'
- | COS, x :: s' -> cos (x) :: s'
- | LOG, x :: s' -> log (x) :: s'
- | EXP, x :: s' -> exp (x) :: s'
- | PUSH x, _ -> x :: s
- | _ -> raise EmptyStack;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement