&& and || in both logic and programs

parent 6a159d62
......@@ -220,10 +220,10 @@ rule token = parse
{ ARROW }
| "<->"
{ LRARROW }
| "/\\"
{ ASYM_AND }
| "\\/"
{ ASYM_OR }
| "&&"
{ AMPAMP }
| "||"
{ BARBAR }
| "\\"
{ LAMBDA }
| "\\?"
......
......@@ -163,7 +163,7 @@
/* symbols */
%token ARROW ASYM_AND ASYM_OR
%token ARROW
%token BACKQUOTE BAR
%token COLON COMMA
%token DOT EQUAL FUNC LAMBDA LTGT
......@@ -177,7 +177,7 @@
/* program symbols */
%token LEFTBRC RIGHTBRC SEMICOLON
%token AMPAMP BARBAR LEFTBRC RIGHTBRC SEMICOLON
/* Precedences */
......@@ -195,8 +195,8 @@
%nonassoc COLON
%right ARROW LRARROW
%right OR ASYM_OR
%right AND ASYM_AND
%right OR BARBAR
%right AND AMPAMP
%nonassoc NOT
%left EQUAL LTGT OP1
%left OP2
......@@ -494,11 +494,11 @@ lexpr:
{ infix_pp $1 PPiff $3 }
| lexpr OR lexpr
{ infix_pp $1 PPor $3 }
| lexpr ASYM_OR lexpr
| lexpr BARBAR lexpr
{ mk_pp (PPnamed (Ident.label "asym_split", infix_pp $1 PPor $3)) }
| lexpr AND lexpr
{ infix_pp $1 PPand $3 }
| lexpr ASYM_AND lexpr
| lexpr AMPAMP lexpr
{ mk_pp (PPnamed (Ident.label "asym_split", infix_pp $1 PPand $3)) }
| NOT lexpr
{ prefix_pp PPnot $2 }
......@@ -931,12 +931,10 @@ expr:
{ mk_expr (Esequence ($1, $3)) }
| assertion_kind annotation
{ mk_expr (Eassert ($1, $2)) }
/*
| expr AMPAMP expr
{ mk_expr (Elazy (LazyAnd, $1, $3)) }
| expr BARBAR expr
{ mk_expr (Elazy (LazyOr, $1, $3)) }
*/
| LET pattern EQUAL expr IN expr
{ match $2.pat_desc with
| PPpvar id -> mk_expr (Elet (id, $4, $6))
......
o refs -> mutable types
X refs -> mutable types
o loadpath: how to retrieve program files? (cannot use "env")
X loadpath: how to retrieve program files? (cannot use "env")
o what about pervasives old, at, label, exn, unit = (), lt_nat
in particular, how to prevent old and at from being used in programs?
......@@ -351,6 +351,12 @@ and dexpr_desc env loc = function
in
DElogic s, dcurrying tyl ty
end
| Ptree.Elazy (op, e1, e2) ->
let e1 = dexpr env e1 in
expected_type e1 (dty_bool env.uc);
let e2 = dexpr env e2 in
expected_type e2 (dty_bool env.uc);
DElazy (op, e1, e2), dty_bool env.uc
| Ptree.Eapply (e1, e2) ->
let e1 = dexpr env e1 in
let e2 = dexpr env e2 in
......@@ -413,12 +419,6 @@ and dexpr_desc env loc = function
let e1 = dexpr env e1 in
expected_type e1 (dty_unit env.uc);
DEloop (dloop_annotation env a, e1), dty_unit env.uc
| Ptree.Elazy (op, e1, e2) ->
let e1 = dexpr env e1 in
expected_type e1 (dty_bool env.uc);
let e2 = dexpr env e2 in
expected_type e2 (dty_bool env.uc);
DElazy (op, e1, e2), dty_bool env.uc
| Ptree.Ematch (e1, bl) ->
let e1 = dexpr env e1 in
let ty1 = e1.dexpr_type in
......
......@@ -13,6 +13,11 @@ module P
(* parameter r : ref int *)
let foo (x : int) =
{ x = 1 }
if x = 1 || absurd then 2 else 3
{ result = 2 }
let f () =
{ }
let r = ref 0 in
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment