Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/boa/boa.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let exec env = function
(* evaluate [e] *)
let v = Eval.eval env e in
Format.printf "%t@." (Eval.print_value v) ;
env
env

| Syntax.Def (x, e) ->
(* define a new global value *)
Expand Down
8 changes: 4 additions & 4 deletions src/boa/eval.ml
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ let eval env e =

| Syntax.If (e1, e2, e3) ->
if get_bool (eval th env e1) then
eval th env e2
eval th env e2
else
eval th env e3
eval th env e3

| Syntax.Skip -> unit_obj

Expand All @@ -145,8 +145,8 @@ let eval env e =

| Syntax.This ->
(match th with
| Some v -> v
| None -> Zoo.error "invalid use of 'this'")
| Some v -> v
| None -> Zoo.error "invalid use of 'this'")

| Syntax.Object lst ->
mk_obj (List.map (fun (x,e) -> (x, ref (eval th env e))) lst)
Expand Down
2 changes: 1 addition & 1 deletion src/boa/example.boa
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ let list = {
isEmpty = fun _ -> this.empty,
getHead = fun _ -> this.head,
getTail = fun _ -> this.tail,

# constructors
nil = fun _ -> this with { empty = true },
cons = fun x -> fun xs -> this with { empty = false, head = x, tail = xs },
Expand Down
2 changes: 1 addition & 1 deletion src/boa/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ rule token = parse
| "fun" { FUN }
| "if" { IF }
| "in" { IN }
| "let" { LET }
| "let" { LET }
| "not" { NOT }
| "or" { OR }
| "skip" { SKIP }
Expand Down
22 changes: 11 additions & 11 deletions src/boa/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ expr:
| app { $1 }
| arith { $1 }
| boolean { $1 }
| IF expr THEN expr ELSE expr { If ($2, $4, $6) }
| IF expr THEN expr ELSE expr { If ($2, $4, $6) }
| FUN VAR ARROW expr { Fun ($2, $4) }
| LET VAR EQUAL expr IN expr { Let ($2, $4, $6) }
| non_app PERIOD VAR ASSIGN expr { Assign ($1, $3, $5) }
Expand All @@ -69,24 +69,24 @@ app:
| non_app non_app { App ($1, $2) }

non_app:
VAR { Var $1 }
VAR { Var $1 }
| THIS { This }
| TRUE { Bool true }
| FALSE { Bool false }
| INT { Int $1 }
| TRUE { Bool true }
| FALSE { Bool false }
| INT { Int $1 }
| SKIP { Skip }
| LPAREN expr RPAREN { $2 }
| LPAREN expr RPAREN { $2 }
| non_app PERIOD VAR { Project ($1, $3) }
| LBRACE fields RBRACE { Object $2 }
| COPY non_app { Copy $2 }
| non_app WITH non_app { With ($1, $3) }

arith:
| expr PLUS expr { ArithOp (Plus, $1, $3) }
| expr MINUS expr { ArithOp (Minus, $1, $3) }
| expr TIMES expr { ArithOp (Times, $1, $3) }
| expr DIVIDE expr { ArithOp (Divide, $1, $3) }
| expr REMAINDER expr { ArithOp (Remainder, $1, $3) }
| expr PLUS expr { ArithOp (Plus, $1, $3) }
| expr MINUS expr { ArithOp (Minus, $1, $3) }
| expr TIMES expr { ArithOp (Times, $1, $3) }
| expr DIVIDE expr { ArithOp (Divide, $1, $3) }
| expr REMAINDER expr { ArithOp (Remainder, $1, $3) }

boolean:
| NOT expr { Not $2 }
Expand Down
2 changes: 1 addition & 1 deletion src/boa/syntax.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type boolop = And | Or
(** Expressions *)
type expr =
| Var of name (** variable *)
| Bool of bool (** boolean constant [true] or [false] *)
| Bool of bool (** boolean constant [true] or [false] *)
| Int of int (** integer constant *)
| ArithOp of arithop * expr * expr (** arithmetical operation [e1 op e2] *)
| Not of expr (** logical negation [not e] *)
Expand Down
2 changes: 1 addition & 1 deletion src/calc/eval.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ let rec eval = function
| Syntax.Times (e1, e2) -> eval e1 * eval e2
| Syntax.Divide (e1, e2) ->
let n2 = eval e2 in
if n2 <> 0 then eval e1 / n2 else Zoo.error "division by zero"
if n2 <> 0 then eval e1 / n2 else Zoo.error "division by zero"
| Syntax.Negate e -> - (eval e)
2 changes: 1 addition & 1 deletion src/calc/syntax.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type expression =
let string_of_expression e =
let rec to_str n e =
let (m, str) = match e with
Numeral n -> (3, string_of_int n)
Numeral n -> (3, string_of_int n)
| Negate e -> (2, "-" ^ (to_str 2 e))
| Times (e1, e2) -> (1, (to_str 1 e1) ^ " * " ^ (to_str 2 e2))
| Divide (e1, e2) -> (1, (to_str 1 e1) ^ " / " ^ (to_str 2 e2))
Expand Down
2 changes: 1 addition & 1 deletion src/comm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Boolean expression `b`:

* boolean constants `true` and `false`
* conjunction `b₁ and b₂`
* disjunction `b₁ or b₂`
* disjunction `b₁ or b₂`
* negation `not b`

Command `c`:
Expand Down
2 changes: 1 addition & 1 deletion src/lambda/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ to call by value and the weak head normal form to call by name.
The file `example.lambda` contains an example session which defines booleans, numbers, and
lists. You can use it as follows:

$ ./lambda.native -l example.lambda
$ ./lambda.native -l example.lambda
pair is defined.
first is defined.
second is defined.
Expand Down
38 changes: 19 additions & 19 deletions src/levy/eval.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ let rec comp env e =

| Syntax.If (e1, e2, e3) ->
(match expr env e1 with
| VBool true -> comp env e2
| VBool false -> comp env e3
| _ -> runtime_error ~loc:(e1.Zoo.loc) "boolean expected")
| VBool true -> comp env e2
| VBool false -> comp env e3
| _ -> runtime_error ~loc:(e1.Zoo.loc) "boolean expected")

| Syntax.Apply (e1, e2) ->
(match comp env e1 with
| VFun (env', x, e) ->
| VFun (env', x, e) ->
let v2 = expr env e2 in
comp ((x,v2)::env') e
| _ -> runtime_error ~loc:(e1.Zoo.loc) "function expected")
| _ -> runtime_error ~loc:(e1.Zoo.loc) "function expected")

| Syntax.Let (x, e1, e2) ->
let v = expr env e1 in
Expand All @@ -50,8 +50,8 @@ let rec comp env e =

| Syntax.Force e ->
(match expr env e with
| VThunk (env, e) -> comp env e
| _ -> runtime_error ~loc:(e.Zoo.loc) "thunk expected in force")
| VThunk (env, e) -> comp env e
| _ -> runtime_error ~loc:(e.Zoo.loc) "thunk expected in force")

| Syntax.Rec (x, _, e') -> comp ((x, VThunk (env, e)) :: env) e'

Expand All @@ -71,9 +71,9 @@ and expr env {Zoo.data=e; loc} =

| Syntax.Var x ->
(try
List.assoc x env
List.assoc x env
with
Not_found -> runtime_error ~loc "unknown variable %s" x)
Not_found -> runtime_error ~loc "unknown variable %s" x)

| Syntax.Int k -> VInt k

Expand All @@ -83,27 +83,27 @@ and expr env {Zoo.data=e; loc} =

| Syntax.Times (e1, e2) ->
(match (expr env e1), (expr env e2) with
| VInt k1, VInt k2 -> VInt (k1 * k2)
| _ -> runtime_error ~loc "integers expected in multiplication")
| VInt k1, VInt k2 -> VInt (k1 * k2)
| _ -> runtime_error ~loc "integers expected in multiplication")

| Syntax.Plus (e1, e2) ->
(match (expr env e1), (expr env e2) with
| VInt k1, VInt k2 -> VInt (k1 + k2)
| _ -> runtime_error ~loc "integers expected in addition")
| VInt k1, VInt k2 -> VInt (k1 + k2)
| _ -> runtime_error ~loc "integers expected in addition")

| Syntax.Minus (e1, e2) ->
(match (expr env e1), (expr env e2) with
| VInt k1, VInt k2 -> VInt (k1 - k2)
| _ -> runtime_error ~loc "integers expected in subtraction")
| VInt k1, VInt k2 -> VInt (k1 - k2)
| _ -> runtime_error ~loc "integers expected in subtraction")

| Syntax.Equal (e1, e2) ->
(match (expr env e1), (expr env e2) with
| VInt k1, VInt k2 -> VBool (k1 = k2)
| _ -> runtime_error ~loc "integers expected in =")
| VInt k1, VInt k2 -> VBool (k1 = k2)
| _ -> runtime_error ~loc "integers expected in =")
| Syntax.Less (e1, e2) ->
(match (expr env e1), (expr env e2) with
| VInt k1, VInt k2 -> VBool (k1 < k2)
| _ -> runtime_error ~loc "integers expected in <")
| VInt k1, VInt k2 -> VBool (k1 < k2)
| _ -> runtime_error ~loc "integers expected in <")

| Syntax.Force _
| Syntax.Return _
Expand Down
2 changes: 1 addition & 1 deletion src/levy/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ rule token = parse
| "if" { IF }
| "in" { IN }
| "is" { IS }
| "let" { LET }
| "let" { LET }
| "rec" { REC }
| "return" { RETURN }
| "then" { THEN }
Expand Down
4 changes: 2 additions & 2 deletions src/levy/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ plain_expr:
| IF expr THEN expr ELSE expr { If ($2, $4, $6) }
| FUN VAR COLON ty DARROW expr { Fun ($2, $4, $6) }
| REC VAR COLON ty IS expr { Rec ($2, $4, $6) }

(* boolean: mark_position(plain_boolean) { $1 } *)
plain_boolean:
| plain_arith { $1 }
Expand Down Expand Up @@ -94,7 +94,7 @@ plain_simple:
| INT { Int $1 }
| TRUE { Bool true }
| FALSE { Bool false }
| LPAREN plain_expr RPAREN { $2 }
| LPAREN plain_expr RPAREN { $2 }

ty: mark_position(plain_ty) { $1 }
plain_ty:
Expand Down
32 changes: 16 additions & 16 deletions src/levy/syntax.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ type value = expr

and expr = expr' Zoo.located
and expr' =
| Var of name (** variable *)
| Int of int (** integer constant *)
| Bool of bool (** boolean constant *)
| Times of value * value (** product [v1 * v2] *)
| Plus of value * value (** sum [v1 + v2] *)
| Minus of value * value (** difference [v1 - v2] *)
| Equal of value * value (** integer equality [v1 = v2] *)
| Less of value * value (** integer comparison [v1 < v2] *)
| Thunk of expr (** thunk [thunk e] *)
| Force of value (** [force v] *)
| Return of value (** [return v] *)
| Do of name * expr * expr (** sequencing [do x <- e1 in e2] *)
| Var of name (** variable *)
| Int of int (** integer constant *)
| Bool of bool (** boolean constant *)
| Times of value * value (** product [v1 * v2] *)
| Plus of value * value (** sum [v1 + v2] *)
| Minus of value * value (** difference [v1 - v2] *)
| Equal of value * value (** integer equality [v1 = v2] *)
| Less of value * value (** integer comparison [v1 < v2] *)
| Thunk of expr (** thunk [thunk e] *)
| Force of value (** [force v] *)
| Return of value (** [return v] *)
| Do of name * expr * expr (** sequencing [do x <- e1 in e2] *)
| Let of name * value * expr (** let-binding [let x = v in e] *)
| If of value * expr * expr (** conditional [if v then e1 else e2] *)
| Fun of name * ltype * expr (** function [fun x:s -> e] *)
| Apply of expr * value (** application [e v] *)
| Rec of name * ltype * expr (** recursion [rec x : t is e] *)
| If of value * expr * expr (** conditional [if v then e1 else e2] *)
| Fun of name * ltype * expr (** function [fun x:s -> e] *)
| Apply of expr * value (** application [e v] *)
| Rec of name * ltype * expr (** recursion [rec x : t is e] *)

(** Toplevel commands *)
type toplevel =
Expand Down
18 changes: 9 additions & 9 deletions src/levy/type_check.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let rec print_vtype ?max_level vty ppf =
match vty with
| VInt -> Format.fprintf ppf "int"
| VBool -> Format.fprintf ppf "bool"
| VForget cty ->
| VForget cty ->
Zoo.print_parens ?max_level ~at_level:2 ppf
"U@ %t"
(print_ctype ~max_level:1 cty)
Expand All @@ -24,7 +24,7 @@ and print_ctype ?max_level cty ppf =
match cty with
| CFree vty ->
Zoo.print_parens ?max_level ~at_level:2 ppf
"F@ %t"
"F@ %t"
(print_vtype ~max_level:1 vty)
| CArrow (vty, cty) ->
Zoo.print_parens ?max_level ~at_level:1 ppf
Expand All @@ -44,7 +44,7 @@ and as_vtype {Zoo.data=ty; loc} =
| Syntax.VInt -> VInt
| Syntax.VBool -> VBool
| Syntax.VForget ty -> VForget (as_ctype ty)
| Syntax.CFree _ | Syntax.CArrow _ ->
| Syntax.CFree _ | Syntax.CArrow _ ->
type_error ~loc "this is not a value type"

(** [check ctx ty e] checks that expression [e] has computation
Expand All @@ -71,10 +71,10 @@ and check_ctype ctx cty e =
and vtype_of ctx {Zoo.data=e; loc} =
match e with
| Syntax.Var x ->
(try
List.assoc x ctx
(try
List.assoc x ctx
with
Not_found -> type_error ~loc "unknown identifier %s" x)
Not_found -> type_error ~loc "unknown identifier %s" x)

| Syntax.Int _ -> VInt

Expand Down Expand Up @@ -140,15 +140,15 @@ and ctype_of ctx {Zoo.data=e; loc} =
check_vtype ctx ty1 e2 ;
ty2
| ty ->
type_error ~loc:(e1.Zoo.loc)
type_error ~loc:(e1.Zoo.loc)
"this expression is used as a function but its type is %t"
(print_ctype ty))

| Syntax.Do (x, e1, e2) ->
(match ctype_of ctx e1 with
| CFree ty1 -> ctype_of ((x,ty1)::ctx) e2
| ty -> type_error ~loc:(e1.Zoo.loc)
"this expression is sequenced but its type is %t"
"this expression is sequenced but its type is %t"
(print_ctype ty))

| Syntax.Let (x, e1, e2) ->
Expand Down Expand Up @@ -178,7 +178,7 @@ and ctype_of ctx {Zoo.data=e; loc} =
| Syntax.Minus _
| Syntax.Times _
| Syntax.Equal _
| Syntax.Less _
| Syntax.Less _
| Syntax.Thunk _ ->
type_error ~loc "a computation was expected but a value was encountered"

4 changes: 2 additions & 2 deletions src/minihaskell/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ A lazy functional language with following features:
The file primes.minhs defines the infinite list of prime numbers. You
can load it and try it as follows:

$ ./minihaskell.byte prime.minhs
$ ./minihaskell.byte prime.minhs
val not : bool -> bool
val div : int -> int -> int
val mod : int -> int -> int
Expand All @@ -37,5 +37,5 @@ can load it and try it as follows:
:: 383 :: 389 :: 397 :: 401 :: 409 :: 419 :: 421 :: 431 :: 433
:: 439 :: 443 :: 449 :: 457 :: 461 :: 463 :: 467 :: 479 :: 487
:: 491 :: 499 :: 503 :: 509 :: 521 :: 523 :: ... :: ...
MiniHaskell>
MiniHaskell>
Good bye.
Loading