Skip to content
Browse files

comparisons simplified

  • Loading branch information...
1 parent 27f3f1d commit 95961ac237d56a97f4487d0bfb3168edf18795d3 sumii committed Oct 4, 2005
Showing with 6 additions and 12 deletions.
  1. BIN gaiyou.ppt
  2. +2 −4 kNormal.ml
  3. +3 −3 parser.mly
  4. +0 −2 syntax.ml
  5. +1 −3 typing.ml
View
BIN gaiyou.ppt
Binary file not shown.
View
6 kNormal.ml
@@ -85,7 +85,7 @@ let rec g env = function (* K
insert_let (g env e1)
(fun x -> insert_let (g env e2)
(fun y -> FDiv(x, y), Type.Float))
- | Syntax.Eq _ | Syntax.NEq _ | Syntax.Lt _ | Syntax.LE _ as cmp ->
+ | Syntax.Eq _ | Syntax.LE _ as cmp ->
g env (Syntax.If(cmp, Syntax.Bool(true), Syntax.Bool(false)))
| Syntax.If(Syntax.Not(e1), e2, e3) -> g env (Syntax.If(e1, e3, e2)) (* notによる分岐を変換 (caml2html: knormal_not) *)
| Syntax.If(Syntax.Eq(e1, e2), e3, e4) ->
@@ -95,16 +95,14 @@ let rec g env = function (* K
let e3', t3 = g env e3 in
let e4', t4 = g env e4 in
IfEq(x, y, e3', e4'), t3))
- | Syntax.If(Syntax.NEq(e1, e2), e3, e4) -> g env (Syntax.If(Syntax.Eq(e1, e2), e4, e3))
- | Syntax.If(Syntax.Lt(e1, e2), e3, e4) -> g env (Syntax.If(Syntax.LE(e2, e1), e4, e3))
| Syntax.If(Syntax.LE(e1, e2), e3, e4) ->
insert_let (g env e1)
(fun x -> insert_let (g env e2)
(fun y ->
let e3', t3 = g env e3 in
let e4', t4 = g env e4 in
IfLE(x, y, e3', e4'), t3))
- | Syntax.If(e1, e2, e3) -> g env (Syntax.If(Syntax.NEq(e1, Syntax.Bool(false)), e2, e3)) (* 比較のない分岐を変換 (caml2html: knormal_if) *)
+ | Syntax.If(e1, e2, e3) -> g env (Syntax.If(Syntax.Eq(e1, Syntax.Bool(false)), e3, e2)) (* 比較のない分岐を変換 (caml2html: knormal_if) *)
| Syntax.Let((x, t), e1, e2) ->
let e1', t1 = g env e1 in
let e2', t2 = g (M.add x t env) e2 in
View
6 parser.mly
@@ -88,11 +88,11 @@ exp: /*
| exp EQUAL exp
{ Eq($1, $3) }
| exp LESS_GREATER exp
- { NEq($1, $3) }
+ { Not(Eq($1, $3)) }
| exp LESS exp
- { Lt($1, $3) }
+ { Not(LE($3, $1)) }
| exp GREATER exp
- { Lt($3, $1) }
+ { Not(LE($1, $3)) }
| exp LESS_EQUAL exp
{ LE($1, $3) }
| exp GREATER_EQUAL exp
View
2 syntax.ml
@@ -13,8 +13,6 @@ type t = (* MinCaml
| FMul of t * t
| FDiv of t * t
| Eq of t * t
- | NEq of t * t
- | Lt of t * t
| LE of t * t
| If of t * t * t
| Let of (Id.t * Type.t) * t * t
View
4 typing.ml
@@ -28,8 +28,6 @@ let rec deref_term = function
| Add(e1, e2) -> Add(deref_term e1, deref_term e2)
| Sub(e1, e2) -> Sub(deref_term e1, deref_term e2)
| Eq(e1, e2) -> Eq(deref_term e1, deref_term e2)
- | NEq(e1, e2) -> NEq(deref_term e1, deref_term e2)
- | Lt(e1, e2) -> Lt(deref_term e1, deref_term e2)
| LE(e1, e2) -> LE(deref_term e1, deref_term e2)
| FNeg(e) -> FNeg(deref_term e)
| FAdd(e1, e2) -> FAdd(deref_term e1, deref_term e2)
@@ -106,7 +104,7 @@ let rec g env e = (*
unify Type.Float (g env e1);
unify Type.Float (g env e2);
Type.Float
- | Eq(e1, e2) | NEq(e1, e2) | Lt(e1, e2) | LE(e1, e2) ->
+ | Eq(e1, e2) | LE(e1, e2) ->
unify (g env e1) (g env e2);
Type.Bool
| If(e1, e2, e3) ->

0 comments on commit 95961ac

Please sign in to comment.
Something went wrong with that request. Please try again.