-
Notifications
You must be signed in to change notification settings - Fork 0
/
logicAndArit.ml
executable file
·55 lines (43 loc) · 1.65 KB
/
logicAndArit.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
open Javasyntax;;
open Display ;;
type expreArit =
| Constante of int
| Suma of expreArit * expreArit
| Resta of expreArit * expreArit
| Division of expreArit * expreArit
| Multiplicacion of expreArit * expreArit;;
type expreLogic =
| Literal2 of literal
| And of expreLogic * expreLogic
| Or of expreLogic * expreLogic
| Not of expreLogic ;;
type relOp =
| Mayor of relOp * relOp
| MayorIgual of relOp * relOp
| Menor of relOp * relOp
| MenorIgual of relOp * relOp
| Igual of relOp * relOp
| Diferente of relOp * relOp ;;
let rec moduloAritmetico operando =
match operando with
Constante(t1)-> t1
| Suma(t1,t2) -> (moduloAritmetico t1) + (moduloAritmetico t2)
| Resta(t1,t2) -> (moduloAritmetico t1) - (moduloAritmetico t2)
| Division(t1,t2) -> (moduloAritmetico t1) / (moduloAritmetico t2)
| Multiplicacion(t1,t2) -> (moduloAritmetico t1) * (moduloAritmetico t2);;
let relOpEval r =
match r with
| Mayor(t1,t2) -> t1 > t2
| MayorIgual(t1,t2) -> t1 >= t2
| Menor(t1,t2) -> t1 < t2
| MenorIgual(t1,t2) -> t1 <= t2
| Igual(t1,t2) -> t1 == t2
| Diferente(t1,t2) -> t1 != t2;;
relOpEval (Mayor(Literal2(IntLit(20)) , Literal2(IntLit(15))));;
(**
relOpEval(MayorIgual(LiIntLit(20)) , Literal2(IntLit(15))));;
relOpEval(Menor(Literal2(IntLit(20)) , Literal2(IntLit(15)) )) ;;
relOpEval(MenorIgual(Literal2(IntLit(20)) , Literal2(IntLit(20)))) ;;
relOpEval(Igual(Literal2(IntLit(30)) , Literal2(IntLit(30))));;
relOpEval(Diferente(Literal2(IntLit(20)) , Literal2(IntLit(15)))) ;;
**)