commit 97aa184a7861ea69fbda3496105b39df8f9f39d3
parent 991446f48de7909c6830189ac83c7f71f6662f07
Author: Robert Russell <robertrussell.72001@gmail.com>
Date: Mon, 11 Dec 2023 13:59:27 -0800
Concrete to abstract syntax conversion
Diffstat:
| M | .gitignore | | | 4 | +++- |
| M | Makefile | | | 8 | ++++---- |
| A | abstract.ml | | | 26 | ++++++++++++++++++++++++++ |
| A | concrete.ml | | | 54 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | conctoabs.ml | | | 82 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| M | parser.ml | | | 543 | ++++++++++++++++++++++++++++++++++++++++++++----------------------------------- |
| M | parser.mly | | | 70 | +++++++++++++++++++++++++++++++++++++++++----------------------------- |
| D | raw.ml | | | 52 | ---------------------------------------------------- |
8 files changed, 510 insertions(+), 329 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,6 +1,8 @@
+*.o
*.cm*
*.mli
-test
lexer.ml
parser.ml
parser.output
+test
+main
diff --git a/Makefile b/Makefile
@@ -1,13 +1,13 @@
-main: surf.ml parser.ml lexer.ml main.ml
+main: common.ml concrete.ml parser.ml lexer.ml abstract.ml conctoabs.ml
ocamlfind ocamlopt -o $@ -g -linkpkg -package zarith $^
lexer.ml: lexer.mll
ocamllex lexer.mll
parser.ml: parser.mly
- ocamlyacc parser.mly
+ ocamlyacc -v parser.mly
rm parser.mli # Hack
.PHONY: clean
clean:
- rm -f main *.o *.cm* lexer.ml parser.ml parser.mli
-\ No newline at end of file
+ rm -f main *.o *.cm* lexer.ml parser.ml parser.mli parser.output
+\ No newline at end of file
diff --git a/abstract.ml b/abstract.ml
@@ -0,0 +1,26 @@
+open Common
+
+type term =
+| Let of patt * term * term
+| Match of term * case list
+| Check of term * term
+| App of term * term list
+| Access of term * ident
+| Index of term * term
+| Deref of term
+| Fn of patt list * term
+| FnType of annot list * term
+| Data of ident * (ident * term) list
+| DataType of (ident * annot list) list
+| Int of Z.t
+| Hole
+| Ident of ident
+and patt =
+| PWild
+| PBind of ident
+| PAnnot of annot
+| PAssign of term
+| PData of ident * (ident * patt) list
+| PInt of Z.t
+and annot = Annot of patt * term
+and case = Case of {patt: patt; guard: term option; body: term}
diff --git a/concrete.ml b/concrete.ml
@@ -0,0 +1,54 @@
+open Common
+
+type expr =
+| Let of expr * expr * expr
+| Seq of expr * expr
+| Match of expr * case list
+| If of expr * expr * expr
+| Iff of expr * expr
+| Annot of expr * expr
+| Add of expr * expr
+| Mul of expr * expr
+| App of expr * expr list
+| Access of expr * ident
+| Index of expr * expr
+| Deref of expr
+| Fn of expr list * expr
+| FnType of expr list * expr
+| Variant of ident * expr list
+| VariantType of (ident * expr list) list
+| Tuple of expr list
+| TupleType of expr list
+| Record of (ident * expr) list
+| RecordType of (ident * expr) list
+| Unit
+| Int of Z.t
+| Underscore
+| Ident of ident
+and case = Case of {patt: expr; guard: expr option; body: expr}
+
+(*
+let rec string_of_expr m e =
+ let sp = string_of_patt in
+ let se = string_of_expr in
+ let (c, s) = match e with
+ | Let (p, a, b) -> (0, "let " ^ sp 0 p ^ " = " ^ se 1 a ^ "; " ^ se 0 b)
+ | If (c, t, f) -> (0, "if " ^ se 1 c ^ " then " ^ se 1 t ^ " else " ^ se 1 f)
+ | Fn (p, e) -> (1, "@(" ^ sp 0 p ^ ") -> " ^ se 1 e)
+ | Pi (p, e) -> (1, "#(" ^ sp 0 p ^ ") -> " ^ se 1 e)
+ | Hint (a, b) -> (1, se 2 a ^ " : " ^ se 1 b)
+ | Plus (a, b) -> (2, se 2 a ^ " + " ^ se 3 b)
+ | Asterisk (a, b) -> (3, se 3 a ^ " * " ^ se 4 b)
+ | Apposition (a, b) -> (4, se 4 a ^ " " ^ se 5 b)
+ | Var x -> (5, x)
+ | Int z -> (5, Z.to_string z) in
+ if c < m then "(" ^ s ^ ")" else s
+
+and string_of_patt m p =
+ let sp = string_of_patt in
+ let se = string_of_expr in
+ let (c, s) = match p with
+ | Annot (p, e) -> (0, sp 1 p ^ " : " ^ se 1 e)
+ | Wild x -> (1, x) in
+ if c < m then "(" ^ s ^ ")" else s
+*)
diff --git a/conctoabs.ml b/conctoabs.ml
@@ -0,0 +1,82 @@
+open Common
+module C = Concrete
+module A = Abstract
+
+exception InvalidPattern
+
+let rec map_ordered f =
+ let rec go i = function
+ | [] -> []
+ | e :: es -> (string_of_int i, f e) :: go (i + 1) es in
+ go 0
+
+let rec map_named f = function
+| [] -> []
+| (x, e) :: xes -> (x, f e) :: map_named f xes
+
+let rec term = function
+| C.Let (p, a, b) -> A.Let (patt p, term a, term b)
+| C.Seq (a, b) -> A.Let (A.PWild, term a, term b)
+| C.Match (a, cs) -> A.Match (term a, List.map case cs)
+| C.If (a, b, c) -> A.Match (term a, [
+ A.Case {patt = A.PData ("true", []); guard = None; body = term b};
+ A.Case {patt = A.PWild; guard = None; body = term c};
+ ])
+| C.Iff (a, b) -> A.Match (term a, [
+ A.Case {patt = A.PData ("true", []); guard = None; body = term b};
+ A.Case {patt = A.PWild; guard = None; body = A.Data ("", [])};
+ ])
+| C.Annot (a, b) -> A.Check (term a, term b)
+| C.Add (a, b) -> A.App (A.Ident "`+", [term a; term b])
+| C.Mul (a, b) -> A.App (A.Ident "`*", [term a; term b])
+| C.App (a, bs) -> A.App (term a, List.map term bs)
+| C.Access (a, x) -> A.Access (term a, x)
+| C.Index (a, b) -> A.Index (term a, term b)
+| C.Deref a -> A.Deref (term a)
+| C.Fn (ps, a) -> A.Fn (List.map patt ps, term a)
+| C.FnType (anns, cod) -> A.FnType (List.map annot anns, term cod)
+| C.Variant (x, es) -> A.Data (x, map_ordered term es)
+| C.VariantType vs -> A.DataType (map_named (List.map annot) vs)
+| C.Tuple es -> A.Data ("", map_ordered term es)
+| C.TupleType anns -> A.DataType [("", List.map annot anns)]
+| C.Record fs -> A.Data ("", map_named term fs)
+| C.RecordType fds ->
+ let fd_to_ann (x, e) = A.Annot (A.PBind x, term e) in
+ A.DataType [("", List.map fd_to_ann fds)]
+| C.Unit -> A.Data ("", [])
+| C.Int n -> A.Int n
+| C.Underscore -> A.Hole
+| C.Ident x -> A.Ident x
+
+and patt = function
+| C.Let _ -> raise InvalidPattern
+| C.Seq _ -> raise InvalidPattern
+| C.Match _ -> raise InvalidPattern
+| C.If _ -> raise InvalidPattern
+| C.Iff _ -> raise InvalidPattern
+| C.Annot (p, a) -> A.PAnnot (A.Annot (patt p, term a))
+| C.Add _ -> raise InvalidPattern (* n + k patterns? *)
+| C.Mul _ -> raise InvalidPattern
+| C.App _ -> raise InvalidPattern
+| C.Access _ -> raise InvalidPattern
+| C.Index _ -> raise InvalidPattern
+| C.Deref a -> A.PAssign (term a)
+| C.Fn _ -> raise InvalidPattern
+| C.FnType _ -> raise InvalidPattern
+| C.Variant (x, es) -> A.PData (x, map_ordered patt es)
+| C.VariantType _ -> raise InvalidPattern
+| C.Tuple es -> A.PData ("", map_ordered patt es)
+| C.TupleType _ -> raise InvalidPattern
+| C.Record xes -> A.PData ("", map_named patt xes)
+| C.RecordType _ -> raise InvalidPattern
+| C.Unit -> A.PData ("", [])
+| C.Int n -> A.PInt n
+| C.Underscore -> A.PWild
+| C.Ident x -> A.PBind x
+
+and case (C.Case {patt = p; guard = g; body = b}) =
+ A.Case {patt = patt p; guard = Option.map term g; body = term b}
+
+and annot = function
+| C.Annot (a, b) -> A.Annot (patt a, term b)
+| b -> A.Annot (A.PWild, term b)
diff --git a/parser.ml b/parser.ml
@@ -29,7 +29,7 @@ type token =
| FN
| IDENT of (
# 16 "parser.mly"
- Surf.ident
+ Common.ident
# 34 "parser.ml"
)
| INT of (
@@ -41,7 +41,7 @@ type token =
open Parsing
let _ = parse_error;;
# 2 "parser.mly"
-open Surf
+open Concrete
# 46 "parser.ml"
let yytransl_const = [|
0 (* EOF *);
@@ -84,103 +84,108 @@ let yylhs = "\255\255\
\003\000\003\000\006\000\006\000\006\000\007\000\007\000\009\000\
\009\000\010\000\010\000\010\000\011\000\011\000\011\000\011\000\
\013\000\013\000\013\000\013\000\013\000\013\000\013\000\013\000\
-\012\000\012\000\004\000\004\000\004\000\016\000\016\000\005\000\
-\005\000\005\000\008\000\014\000\014\000\014\000\017\000\015\000\
-\015\000\015\000\018\000\000\000"
+\013\000\004\000\004\000\004\000\017\000\017\000\005\000\005\000\
+\005\000\012\000\012\000\014\000\014\000\014\000\018\000\015\000\
+\015\000\015\000\019\000\008\000\020\000\020\000\020\000\016\000\
+\016\000\016\000\021\000\000\000"
let yylen = "\002\000\
\005\000\003\000\001\000\005\000\006\000\004\000\004\000\001\000\
\003\000\001\000\003\000\003\000\001\000\003\000\001\000\003\000\
\001\000\003\000\003\000\001\000\003\000\005\000\002\000\001\000\
-\001\000\001\000\003\000\003\000\003\000\001\000\003\000\003\000\
-\002\000\000\000\003\000\001\000\000\000\005\000\003\000\003\000\
-\001\000\000\000\005\000\003\000\001\000\000\000\003\000\003\000\
+\001\000\001\000\003\000\003\000\003\000\001\000\003\000\002\000\
+\003\000\003\000\001\000\000\000\005\000\003\000\003\000\001\000\
+\000\000\002\000\000\000\003\000\001\000\000\000\003\000\003\000\
+\001\000\000\000\003\000\005\000\003\000\001\000\000\000\003\000\
\001\000\000\000\003\000\002\000"
let yydefred = "\000\000\
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
-\000\000\000\000\000\000\025\000\026\000\052\000\000\000\000\000\
+\000\000\000\000\000\000\025\000\026\000\060\000\000\000\000\000\
\000\000\000\000\000\000\000\000\017\000\000\000\024\000\000\000\
+\000\000\000\000\032\000\000\000\000\000\000\000\000\000\000\000\
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
-\000\000\000\000\000\000\000\000\000\000\000\000\000\000\023\000\
-\030\000\000\000\000\000\019\000\000\000\028\000\032\000\000\000\
-\000\000\027\000\000\000\029\000\000\000\031\000\000\000\000\000\
-\000\000\000\000\002\000\000\000\000\000\009\000\011\000\000\000\
-\012\000\016\000\000\000\021\000\018\000\033\000\040\000\000\000\
-\047\000\044\000\051\000\048\000\000\000\006\000\007\000\000\000\
-\000\000\000\000\000\000\000\000\043\000\000\000\001\000\000\000\
-\000\000\004\000\000\000\022\000\005\000\039\000\000\000\035\000\
-\000\000\038\000"
+\000\000\000\000\023\000\030\000\000\000\000\000\019\000\000\000\
+\028\000\033\000\000\000\000\000\027\000\000\000\000\000\029\000\
+\000\000\000\000\031\000\000\000\000\000\000\000\000\000\002\000\
+\000\000\000\000\009\000\011\000\000\000\012\000\016\000\000\000\
+\021\000\018\000\042\000\039\000\000\000\000\000\047\000\044\000\
+\051\000\048\000\059\000\056\000\000\000\006\000\007\000\000\000\
+\000\000\000\000\000\000\000\000\000\000\052\000\000\000\001\000\
+\000\000\000\000\004\000\000\000\022\000\053\000\005\000\038\000\
+\000\000\034\000\000\000\037\000"
let yydgoto = "\002\000\
-\014\000\025\000\016\000\090\000\026\000\017\000\018\000\019\000\
-\020\000\021\000\022\000\052\000\023\000\030\000\034\000\091\000\
-\031\000\035\000"
+\014\000\015\000\016\000\098\000\026\000\017\000\018\000\019\000\
+\020\000\021\000\022\000\055\000\023\000\031\000\034\000\037\000\
+\099\000\032\000\035\000\086\000\038\000"
-let yysindex = "\012\000\
-\099\255\000\000\245\254\099\255\099\255\023\255\099\255\099\255\
-\099\255\099\255\099\255\000\000\000\000\000\000\052\255\040\255\
-\066\255\024\255\063\255\053\255\000\000\073\255\000\000\120\255\
-\072\255\064\255\067\255\044\255\060\255\065\255\080\255\074\255\
-\084\255\076\255\096\255\075\255\077\255\091\255\099\255\099\255\
-\083\255\005\255\005\255\005\255\005\255\005\255\251\254\000\000\
-\000\000\073\255\073\255\000\000\099\255\000\000\000\000\099\255\
-\099\255\000\000\023\255\000\000\099\255\000\000\099\255\099\255\
-\099\255\099\255\000\000\106\255\005\255\000\000\000\000\053\255\
-\000\000\000\000\099\255\000\000\000\000\000\000\000\000\102\255\
-\000\000\000\000\000\000\000\000\087\255\000\000\000\000\099\255\
-\022\255\100\255\118\255\110\255\000\000\099\255\000\000\099\255\
-\099\255\000\000\005\255\000\000\000\000\000\000\116\255\000\000\
-\099\255\000\000"
+let yysindex = "\015\000\
+\125\255\000\000\247\254\150\255\101\255\023\255\013\255\017\255\
+\125\255\125\255\150\255\000\000\000\000\000\000\024\255\029\255\
+\046\255\018\255\052\255\038\255\000\000\074\255\000\000\158\255\
+\059\255\056\255\000\000\057\255\050\255\043\255\058\255\071\255\
+\072\255\062\255\073\255\068\255\065\255\083\255\066\255\069\255\
+\080\255\125\255\125\255\075\255\150\255\150\255\150\255\150\255\
+\150\255\251\254\000\000\000\000\074\255\074\255\000\000\150\255\
+\000\000\000\000\125\255\150\255\000\000\023\255\150\255\000\000\
+\013\255\125\255\000\000\017\255\125\255\125\255\125\255\000\000\
+\093\255\150\255\000\000\000\000\038\255\000\000\000\000\125\255\
+\000\000\000\000\000\000\000\000\094\255\087\255\000\000\000\000\
+\000\000\000\000\000\000\000\000\081\255\000\000\000\000\125\255\
+\027\255\086\255\105\255\097\255\125\255\000\000\125\255\000\000\
+\125\255\125\255\000\000\150\255\000\000\000\000\000\000\000\000\
+\107\255\000\000\125\255\000\000"
let yyrindex = "\000\000\
-\000\000\000\000\000\000\117\255\000\000\119\255\121\255\122\255\
-\000\000\000\000\127\255\000\000\000\000\000\000\003\000\182\000\
+\000\000\000\000\000\000\108\255\000\000\104\255\103\255\106\255\
+\000\000\000\000\114\255\000\000\000\000\000\000\003\000\165\000\
\132\000\158\000\001\000\082\000\000\000\030\000\000\000\056\000\
-\034\255\000\000\000\000\126\255\000\000\000\000\128\255\000\000\
-\000\000\000\000\123\255\000\000\000\000\000\000\000\000\000\000\
+\012\255\000\000\000\000\000\000\113\255\000\000\000\000\112\255\
+\000\000\000\000\115\255\000\000\000\000\116\255\000\000\000\000\
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
-\000\000\056\000\056\000\000\000\105\255\000\000\000\000\117\255\
-\004\255\000\000\119\255\000\000\000\000\000\000\122\255\000\000\
-\000\000\000\000\000\000\000\000\124\255\000\000\000\000\108\000\
+\000\000\000\000\000\000\000\000\056\000\056\000\000\000\020\255\
+\000\000\000\000\127\255\007\255\000\000\104\255\000\000\000\000\
+\103\255\000\000\000\000\106\255\000\000\000\000\000\000\000\000\
+\000\000\119\255\000\000\000\000\108\000\000\000\000\000\000\000\
+\000\000\000\000\000\000\000\000\128\255\000\000\000\000\000\000\
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
-\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
-\000\000\000\000\129\255\000\000\000\000\000\000\000\000\000\000\
-\000\000\000\000\124\255\000\000\000\000\000\000\000\000\000\000\
-\000\000\000\000"
+\000\000\000\000\126\255\000\000\127\255\000\000\000\000\000\000\
+\000\000\000\000\000\000\119\255\000\000\000\000\000\000\000\000\
+\000\000\000\000\000\000\000\000"
let yygindex = "\000\000\
-\253\255\255\255\224\255\045\000\013\000\238\255\000\000\004\000\
-\101\000\100\000\246\255\007\000\000\000\091\000\088\000\000\000\
-\000\000\000\000"
+\253\255\251\255\007\000\035\000\255\255\217\255\000\000\249\255\
+\098\000\097\000\246\255\236\255\000\000\086\000\084\000\083\000\
+\000\000\000\000\000\000\054\000\000\000"
-let yytablesize = 464
-let yytable = "\015\000\
-\030\000\027\000\003\000\028\000\042\000\075\000\033\000\036\000\
-\037\000\070\000\003\000\050\000\001\000\051\000\004\000\005\000\
-\024\000\006\000\042\000\032\000\007\000\008\000\076\000\038\000\
-\071\000\049\000\073\000\049\000\029\000\020\000\096\000\043\000\
-\012\000\013\000\041\000\067\000\089\000\015\000\068\000\051\000\
-\051\000\041\000\044\000\097\000\039\000\041\000\056\000\049\000\
-\041\000\049\000\040\000\041\000\039\000\049\000\049\000\034\000\
-\077\000\078\000\040\000\083\000\041\000\033\000\085\000\086\000\
-\087\000\079\000\089\000\042\000\080\000\081\000\045\000\092\000\
-\046\000\015\000\053\000\054\000\047\000\048\000\055\000\058\000\
-\059\000\015\000\004\000\005\000\095\000\006\000\015\000\057\000\
-\007\000\008\000\061\000\060\000\101\000\062\000\102\000\103\000\
-\063\000\064\000\066\000\069\000\012\000\013\000\065\000\106\000\
-\003\000\042\000\088\000\014\000\004\000\005\000\094\000\006\000\
-\042\000\093\000\007\000\008\000\042\000\098\000\099\000\042\000\
-\009\000\100\000\042\000\010\000\105\000\011\000\012\000\013\000\
-\042\000\004\000\005\000\010\000\006\000\046\000\042\000\007\000\
-\008\000\003\000\042\000\050\000\049\000\037\000\045\000\104\000\
-\072\000\074\000\036\000\012\000\013\000\082\000\084\000\000\000\
-\000\000\000\000\000\000\000\000\000\000\013\000\000\000\000\000\
-\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
-\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
-\000\000\000\000\000\000\000\000\000\000\008\000\000\000\000\000\
-\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
+let yytablesize = 447
+let yytable = "\029\000\
+\030\000\028\000\003\000\039\000\040\000\080\000\076\000\041\000\
+\078\000\041\000\025\000\053\000\040\000\054\000\052\000\001\000\
+\052\000\025\000\024\000\040\000\041\000\041\000\081\000\040\000\
+\042\000\046\000\040\000\041\000\030\000\020\000\043\000\041\000\
+\082\000\083\000\041\000\105\000\047\000\073\000\072\000\052\000\
+\033\000\052\000\054\000\054\000\036\000\052\000\052\000\045\000\
+\106\000\044\000\042\000\075\000\059\000\085\000\084\000\043\000\
+\043\000\049\000\087\000\048\000\091\000\056\000\025\000\093\000\
+\094\000\095\000\025\000\057\000\058\000\089\000\060\000\062\000\
+\061\000\063\000\066\000\065\000\100\000\050\000\051\000\064\000\
+\097\000\015\000\067\000\004\000\005\000\068\000\006\000\071\000\
+\069\000\007\000\008\000\074\000\104\000\096\000\070\000\085\000\
+\101\000\111\000\102\000\112\000\113\000\012\000\013\000\107\000\
+\103\000\108\000\003\000\014\000\109\000\116\000\004\000\005\000\
+\027\000\006\000\097\000\115\000\007\000\008\000\046\000\041\000\
+\050\000\041\000\009\000\058\000\003\000\010\000\045\000\011\000\
+\012\000\013\000\003\000\010\000\049\000\057\000\004\000\005\000\
+\036\000\006\000\055\000\054\000\007\000\008\000\114\000\035\000\
+\077\000\079\000\009\000\088\000\090\000\010\000\092\000\011\000\
+\012\000\013\000\110\000\003\000\000\000\013\000\000\000\004\000\
+\005\000\000\000\006\000\000\000\008\000\007\000\008\000\004\000\
+\005\000\000\000\006\000\000\000\000\000\007\000\008\000\000\000\
+\000\000\012\000\013\000\000\000\000\000\000\000\000\000\000\000\
+\000\000\012\000\013\000\000\000\000\000\000\000\000\000\000\000\
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
@@ -196,10 +201,10 @@ let yytable = "\015\000\
\020\000\000\000\000\000\000\000\020\000\020\000\020\000\000\000\
\000\000\020\000\000\000\000\000\020\000\000\000\000\000\020\000\
\020\000\020\000\020\000\020\000\020\000\020\000\000\000\020\000\
-\034\000\034\000\034\000\000\000\000\000\000\000\034\000\034\000\
-\034\000\000\000\000\000\034\000\000\000\000\000\034\000\000\000\
-\000\000\034\000\034\000\034\000\034\000\034\000\034\000\034\000\
-\000\000\034\000\015\000\015\000\015\000\000\000\000\000\000\000\
+\043\000\043\000\043\000\000\000\000\000\000\000\043\000\043\000\
+\043\000\000\000\000\000\043\000\000\000\000\000\043\000\000\000\
+\000\000\043\000\043\000\043\000\043\000\043\000\043\000\043\000\
+\000\000\043\000\015\000\015\000\015\000\000\000\000\000\000\000\
\015\000\015\000\015\000\000\000\000\000\015\000\000\000\000\000\
\015\000\000\000\000\000\015\000\015\000\000\000\015\000\015\000\
\015\000\015\000\000\000\015\000\014\000\014\000\014\000\000\000\
@@ -209,38 +214,36 @@ let yytable = "\015\000\
\000\000\000\000\010\000\010\000\010\000\000\000\000\000\010\000\
\000\000\000\000\010\000\000\000\000\000\010\000\000\000\000\000\
\010\000\010\000\010\000\010\000\000\000\010\000\013\000\013\000\
-\013\000\000\000\000\000\000\000\013\000\000\000\013\000\000\000\
-\000\000\013\000\000\000\000\000\013\000\000\000\000\000\013\000\
-\000\000\000\000\013\000\013\000\013\000\013\000\008\000\013\000\
-\008\000\000\000\000\000\000\000\008\000\008\000\008\000\000\000\
-\000\000\008\000\000\000\000\000\008\000\000\000\000\000\008\000\
-\000\000\000\000\000\000\000\000\008\000\008\000\000\000\008\000"
+\013\000\000\000\000\000\000\000\013\000\008\000\013\000\008\000\
+\000\000\013\000\000\000\008\000\013\000\008\000\000\000\013\000\
+\008\000\000\000\013\000\013\000\013\000\013\000\008\000\013\000\
+\000\000\000\000\000\000\008\000\008\000\000\000\008\000"
-let yycheck = "\001\000\
-\000\000\005\000\000\000\005\000\001\001\011\001\008\000\009\000\
-\010\000\042\000\006\001\022\000\001\000\024\000\010\001\011\001\
-\028\001\013\001\015\001\007\000\016\001\017\001\028\001\011\000\
-\043\000\022\000\045\000\024\000\006\001\000\000\009\001\008\001\
-\028\001\029\001\001\001\039\000\069\000\039\000\040\000\050\000\
-\051\000\008\001\019\001\022\001\001\001\012\001\003\001\044\000\
-\015\001\046\000\007\001\018\001\001\001\050\000\051\000\000\000\
-\050\000\051\000\007\001\061\000\021\001\063\000\064\000\065\000\
-\066\000\053\000\099\000\002\001\056\000\057\000\008\001\075\000\
-\020\001\075\000\003\001\012\001\004\001\005\001\012\001\015\001\
-\001\001\000\000\010\001\011\001\088\000\013\001\088\000\028\001\
-\016\001\017\001\007\001\018\001\094\000\018\001\096\000\097\000\
-\001\001\023\001\008\001\017\001\028\001\029\001\026\001\105\000\
-\006\001\001\001\001\001\000\000\010\001\011\001\024\001\013\001\
-\008\001\012\001\016\001\017\001\012\001\018\001\001\001\015\001\
-\022\001\012\001\018\001\025\001\009\001\027\001\028\001\029\001\
-\012\001\010\001\011\001\000\000\013\001\015\001\008\001\016\001\
-\017\001\012\001\018\001\018\001\018\001\018\001\015\001\099\000\
-\044\000\046\000\018\001\028\001\029\001\059\000\063\000\255\255\
-\255\255\255\255\255\255\255\255\255\255\000\000\255\255\255\255\
-\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
-\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
-\255\255\255\255\255\255\255\255\255\255\000\000\255\255\255\255\
-\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
+let yycheck = "\005\000\
+\000\000\005\000\000\000\009\000\010\000\011\001\046\000\001\001\
+\048\000\011\000\004\000\022\000\001\001\024\000\022\000\001\000\
+\024\000\011\000\028\001\008\001\001\001\015\001\028\001\012\001\
+\001\001\008\001\015\001\008\001\006\001\000\000\007\001\012\001\
+\053\000\054\000\015\001\009\001\019\001\043\000\042\000\047\000\
+\028\001\049\000\053\000\054\000\028\001\053\000\054\000\002\001\
+\022\001\021\001\001\001\045\000\003\001\059\000\056\000\000\000\
+\007\001\020\001\060\000\008\001\066\000\003\001\056\000\069\000\
+\070\000\071\000\060\000\012\001\012\001\063\000\028\001\001\001\
+\015\001\002\001\007\001\003\001\080\000\004\001\005\001\018\001\
+\074\000\000\000\018\001\010\001\011\001\003\001\013\001\008\001\
+\023\001\016\001\017\001\017\001\096\000\001\001\026\001\101\000\
+\003\001\103\000\012\001\105\000\106\000\028\001\029\001\018\001\
+\024\001\001\001\006\001\000\000\012\001\115\000\010\001\011\001\
+\012\001\013\001\108\000\009\001\016\001\017\001\015\001\012\001\
+\018\001\008\001\022\001\018\001\012\001\025\001\015\001\027\001\
+\028\001\029\001\006\001\000\000\018\001\018\001\010\001\011\001\
+\018\001\013\001\012\001\012\001\016\001\017\001\108\000\018\001\
+\047\000\049\000\022\001\062\000\065\000\025\001\068\000\027\001\
+\028\001\029\001\101\000\006\001\255\255\000\000\255\255\010\001\
+\011\001\255\255\013\001\255\255\000\000\016\001\017\001\010\001\
+\011\001\255\255\013\001\255\255\255\255\016\001\017\001\255\255\
+\255\255\028\001\029\001\255\255\255\255\255\255\255\255\255\255\
+\255\255\028\001\029\001\255\255\255\255\255\255\255\255\255\255\
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
@@ -269,12 +272,10 @@ let yycheck = "\001\000\
\255\255\255\255\007\001\008\001\009\001\255\255\255\255\012\001\
\255\255\255\255\015\001\255\255\255\255\018\001\255\255\255\255\
\021\001\022\001\023\001\024\001\255\255\026\001\001\001\002\001\
-\003\001\255\255\255\255\255\255\007\001\255\255\009\001\255\255\
-\255\255\012\001\255\255\255\255\015\001\255\255\255\255\018\001\
-\255\255\255\255\021\001\022\001\023\001\024\001\001\001\026\001\
-\003\001\255\255\255\255\255\255\007\001\008\001\009\001\255\255\
-\255\255\012\001\255\255\255\255\015\001\255\255\255\255\018\001\
-\255\255\255\255\255\255\255\255\023\001\024\001\255\255\026\001"
+\003\001\255\255\255\255\255\255\007\001\001\001\009\001\003\001\
+\255\255\012\001\255\255\007\001\015\001\009\001\255\255\018\001\
+\012\001\255\255\021\001\022\001\023\001\024\001\018\001\026\001\
+\255\255\255\255\255\255\023\001\024\001\255\255\026\001"
let yynames_const = "\
EOF\000\
@@ -317,34 +318,34 @@ let yyact = [|
; (fun __caml_parser_env ->
let _1 = (Parsing.peek_val __caml_parser_env 4 : 'expr1) in
let _3 = (Parsing.peek_val __caml_parser_env 2 : 'expr1) in
- let _5 = (Parsing.peek_val __caml_parser_env 0 : Surf.expr) in
+ let _5 = (Parsing.peek_val __caml_parser_env 0 : Concrete.expr) in
Obj.repr(
# 29 "parser.mly"
( Let (_1, _3, _5) )
-# 325 "parser.ml"
- : Surf.expr))
+# 326 "parser.ml"
+ : Concrete.expr))
; (fun __caml_parser_env ->
let _1 = (Parsing.peek_val __caml_parser_env 2 : 'expr1) in
- let _3 = (Parsing.peek_val __caml_parser_env 0 : Surf.expr) in
+ let _3 = (Parsing.peek_val __caml_parser_env 0 : Concrete.expr) in
Obj.repr(
# 30 "parser.mly"
( Seq (_1, _3) )
-# 333 "parser.ml"
- : Surf.expr))
+# 334 "parser.ml"
+ : Concrete.expr))
; (fun __caml_parser_env ->
let _1 = (Parsing.peek_val __caml_parser_env 0 : 'expr1) in
Obj.repr(
# 31 "parser.mly"
( _1 )
-# 340 "parser.ml"
- : Surf.expr))
+# 341 "parser.ml"
+ : Concrete.expr))
; (fun __caml_parser_env ->
let _1 = (Parsing.peek_val __caml_parser_env 4 : 'expr2) in
let _4 = (Parsing.peek_val __caml_parser_env 1 : 'cases) in
Obj.repr(
# 33 "parser.mly"
( Match(_1, _4) )
-# 348 "parser.ml"
+# 349 "parser.ml"
: 'expr1))
; (fun __caml_parser_env ->
let _2 = (Parsing.peek_val __caml_parser_env 4 : 'expr1) in
@@ -353,7 +354,7 @@ let yyact = [|
Obj.repr(
# 34 "parser.mly"
( If (_2, _4, _6) )
-# 357 "parser.ml"
+# 358 "parser.ml"
: 'expr1))
; (fun __caml_parser_env ->
let _2 = (Parsing.peek_val __caml_parser_env 2 : 'expr1) in
@@ -361,22 +362,22 @@ let yyact = [|
Obj.repr(
# 35 "parser.mly"
( Iff (_2, _4) )
-# 365 "parser.ml"
+# 366 "parser.ml"
: 'expr1))
; (fun __caml_parser_env ->
- let _2 = (Parsing.peek_val __caml_parser_env 2 : 'expr1_list) in
+ let _2 = (Parsing.peek_val __caml_parser_env 2 : 'annot_list) in
let _4 = (Parsing.peek_val __caml_parser_env 0 : 'expr1) in
Obj.repr(
# 36 "parser.mly"
( Fn (_2, _4) )
-# 373 "parser.ml"
+# 374 "parser.ml"
: 'expr1))
; (fun __caml_parser_env ->
let _1 = (Parsing.peek_val __caml_parser_env 0 : 'expr2) in
Obj.repr(
# 37 "parser.mly"
( _1 )
-# 380 "parser.ml"
+# 381 "parser.ml"
: 'expr1))
; (fun __caml_parser_env ->
let _1 = (Parsing.peek_val __caml_parser_env 2 : 'expr3) in
@@ -384,14 +385,14 @@ let yyact = [|
Obj.repr(
# 39 "parser.mly"
( Annot(_1, _3) )
-# 388 "parser.ml"
+# 389 "parser.ml"
: 'expr2))
; (fun __caml_parser_env ->
let _1 = (Parsing.peek_val __caml_parser_env 0 : 'expr3) in
Obj.repr(
# 40 "parser.mly"
( _1 )
-# 395 "parser.ml"
+# 396 "parser.ml"
: 'expr2))
; (fun __caml_parser_env ->
let _1 = (Parsing.peek_val __caml_parser_env 2 : 'expr4) in
@@ -399,7 +400,7 @@ let yyact = [|
Obj.repr(
# 42 "parser.mly"
( FnType ([_1], _3) )
-# 403 "parser.ml"
+# 404 "parser.ml"
: 'expr3))
; (fun __caml_parser_env ->
let _1 = (Parsing.peek_val __caml_parser_env 2 : 'tuple) in
@@ -407,14 +408,14 @@ let yyact = [|
Obj.repr(
# 43 "parser.mly"
( FnType (_1, _3) )
-# 411 "parser.ml"
+# 412 "parser.ml"
: 'expr3))
; (fun __caml_parser_env ->
let _1 = (Parsing.peek_val __caml_parser_env 0 : 'expr4) in
Obj.repr(
# 44 "parser.mly"
( _1 )
-# 418 "parser.ml"
+# 419 "parser.ml"
: 'expr3))
; (fun __caml_parser_env ->
let _1 = (Parsing.peek_val __caml_parser_env 2 : 'expr4) in
@@ -422,14 +423,14 @@ let yyact = [|
Obj.repr(
# 46 "parser.mly"
( Add (_1, _3) )
-# 426 "parser.ml"
+# 427 "parser.ml"
: 'expr4))
; (fun __caml_parser_env ->
let _1 = (Parsing.peek_val __caml_parser_env 0 : 'expr5) in
Obj.repr(
# 47 "parser.mly"
( _1 )
-# 433 "parser.ml"
+# 434 "parser.ml"
: 'expr4))
; (fun __caml_parser_env ->
let _1 = (Parsing.peek_val __caml_parser_env 2 : 'expr5) in
@@ -437,14 +438,14 @@ let yyact = [|
Obj.repr(
# 49 "parser.mly"
( Mul (_1, _3) )
-# 441 "parser.ml"
+# 442 "parser.ml"
: 'expr5))
; (fun __caml_parser_env ->
let _1 = (Parsing.peek_val __caml_parser_env 0 : 'expr6) in
Obj.repr(
# 50 "parser.mly"
( _1 )
-# 448 "parser.ml"
+# 449 "parser.ml"
: 'expr5))
; (fun __caml_parser_env ->
let _1 = (Parsing.peek_val __caml_parser_env 2 : 'expr7) in
@@ -453,247 +454,303 @@ let yyact = [|
Obj.repr(
# 52 "parser.mly"
( App (_1, _2 :: _3) )
-# 457 "parser.ml"
+# 458 "parser.ml"
: 'expr6))
; (fun __caml_parser_env ->
- let _2 = (Parsing.peek_val __caml_parser_env 1 : Surf.ident) in
+ let _2 = (Parsing.peek_val __caml_parser_env 1 : Common.ident) in
let _3 = (Parsing.peek_val __caml_parser_env 0 : 'expr7_apposition) in
Obj.repr(
# 53 "parser.mly"
- ( Cons (_2, _3) )
-# 465 "parser.ml"
+ ( Variant (_2, _3) )
+# 466 "parser.ml"
: 'expr6))
; (fun __caml_parser_env ->
let _1 = (Parsing.peek_val __caml_parser_env 0 : 'expr7) in
Obj.repr(
# 54 "parser.mly"
( _1 )
-# 472 "parser.ml"
+# 473 "parser.ml"
: 'expr6))
; (fun __caml_parser_env ->
let _1 = (Parsing.peek_val __caml_parser_env 2 : 'expr7) in
- let _3 = (Parsing.peek_val __caml_parser_env 0 : Surf.ident) in
+ let _3 = (Parsing.peek_val __caml_parser_env 0 : Common.ident) in
Obj.repr(
# 56 "parser.mly"
( Access (_1, _3) )
-# 480 "parser.ml"
+# 481 "parser.ml"
: 'expr7))
; (fun __caml_parser_env ->
let _1 = (Parsing.peek_val __caml_parser_env 4 : 'expr7) in
- let _4 = (Parsing.peek_val __caml_parser_env 1 : Surf.expr) in
+ let _4 = (Parsing.peek_val __caml_parser_env 1 : Concrete.expr) in
Obj.repr(
# 57 "parser.mly"
( Index (_1, _4) )
-# 488 "parser.ml"
+# 489 "parser.ml"
: 'expr7))
; (fun __caml_parser_env ->
let _1 = (Parsing.peek_val __caml_parser_env 1 : 'expr7) in
Obj.repr(
# 58 "parser.mly"
( Deref _1 )
-# 495 "parser.ml"
+# 496 "parser.ml"
: 'expr7))
; (fun __caml_parser_env ->
let _1 = (Parsing.peek_val __caml_parser_env 0 : 'expr8) in
Obj.repr(
# 59 "parser.mly"
( _1 )
-# 502 "parser.ml"
+# 503 "parser.ml"
: 'expr7))
; (fun __caml_parser_env ->
- let _1 = (Parsing.peek_val __caml_parser_env 0 : Surf.ident) in
+ let _1 = (Parsing.peek_val __caml_parser_env 0 : Common.ident) in
Obj.repr(
# 61 "parser.mly"
- ( Ident _1 )
-# 509 "parser.ml"
+ ( if _1 = "_" then Underscore else Ident _1 )
+# 510 "parser.ml"
: 'expr8))
; (fun __caml_parser_env ->
let _1 = (Parsing.peek_val __caml_parser_env 0 : Z.t) in
Obj.repr(
# 62 "parser.mly"
( Int _1 )
-# 516 "parser.ml"
+# 517 "parser.ml"
: 'expr8))
; (fun __caml_parser_env ->
- let _2 = (Parsing.peek_val __caml_parser_env 1 : 'variants) in
+ let _2 = (Parsing.peek_val __caml_parser_env 1 : 'variant_def_list) in
Obj.repr(
# 63 "parser.mly"
- ( VariantType _2 )
-# 523 "parser.ml"
+ ( VariantType _2 )
+# 524 "parser.ml"
: 'expr8))
; (fun __caml_parser_env ->
- let _2 = (Parsing.peek_val __caml_parser_env 1 : 'expr1_list) in
+ let _2 = (Parsing.peek_val __caml_parser_env 1 : 'annot_list) in
Obj.repr(
# 64 "parser.mly"
( TupleType _2 )
-# 530 "parser.ml"
+# 531 "parser.ml"
: 'expr8))
; (fun __caml_parser_env ->
- let _2 = (Parsing.peek_val __caml_parser_env 1 : 'expr1_list) in
+ let _2 = (Parsing.peek_val __caml_parser_env 1 : 'field_def_list) in
Obj.repr(
# 65 "parser.mly"
- ( RecordType _2 )
-# 537 "parser.ml"
+ ( RecordType _2 )
+# 538 "parser.ml"
: 'expr8))
; (fun __caml_parser_env ->
let _1 = (Parsing.peek_val __caml_parser_env 0 : 'tuple) in
Obj.repr(
# 66 "parser.mly"
( Tuple _1 )
-# 544 "parser.ml"
+# 545 "parser.ml"
: 'expr8))
; (fun __caml_parser_env ->
- let _2 = (Parsing.peek_val __caml_parser_env 1 : 'fields) in
+ let _2 = (Parsing.peek_val __caml_parser_env 1 : 'field_list) in
Obj.repr(
# 67 "parser.mly"
- ( Record _2 )
-# 551 "parser.ml"
+ ( Record _2 )
+# 552 "parser.ml"
: 'expr8))
; (fun __caml_parser_env ->
- let _2 = (Parsing.peek_val __caml_parser_env 1 : Surf.expr) in
Obj.repr(
# 68 "parser.mly"
- ( _2 )
+ ( Unit )
# 558 "parser.ml"
: 'expr8))
; (fun __caml_parser_env ->
- let _1 = (Parsing.peek_val __caml_parser_env 1 : 'expr7) in
- let _2 = (Parsing.peek_val __caml_parser_env 0 : 'expr7_apposition) in
- Obj.repr(
-# 71 "parser.mly"
- ( _1 :: _2 )
-# 566 "parser.ml"
- : 'expr7_apposition))
-; (fun __caml_parser_env ->
+ let _2 = (Parsing.peek_val __caml_parser_env 1 : Concrete.expr) in
Obj.repr(
-# 72 "parser.mly"
- ( [] )
-# 572 "parser.ml"
- : 'expr7_apposition))
+# 69 "parser.mly"
+ ( _2 )
+# 565 "parser.ml"
+ : 'expr8))
; (fun __caml_parser_env ->
let _1 = (Parsing.peek_val __caml_parser_env 2 : 'case) in
let _3 = (Parsing.peek_val __caml_parser_env 0 : 'cases) in
Obj.repr(
-# 75 "parser.mly"
+# 72 "parser.mly"
( _1 :: _3 )
-# 580 "parser.ml"
+# 573 "parser.ml"
: 'cases))
; (fun __caml_parser_env ->
let _1 = (Parsing.peek_val __caml_parser_env 0 : 'case) in
Obj.repr(
-# 76 "parser.mly"
+# 73 "parser.mly"
( [_1] )
-# 587 "parser.ml"
+# 580 "parser.ml"
: 'cases))
; (fun __caml_parser_env ->
Obj.repr(
-# 77 "parser.mly"
+# 74 "parser.mly"
( [] )
-# 593 "parser.ml"
+# 586 "parser.ml"
: 'cases))
; (fun __caml_parser_env ->
let _1 = (Parsing.peek_val __caml_parser_env 4 : 'expr2) in
let _3 = (Parsing.peek_val __caml_parser_env 2 : 'expr1) in
let _5 = (Parsing.peek_val __caml_parser_env 0 : 'expr1) in
Obj.repr(
-# 79 "parser.mly"
- ( Case (_1, Some (_3), _5) )
-# 602 "parser.ml"
+# 76 "parser.mly"
+ ( Case {patt = _1; guard = Some (_3); body = _5} )
+# 595 "parser.ml"
: 'case))
; (fun __caml_parser_env ->
let _1 = (Parsing.peek_val __caml_parser_env 2 : 'expr2) in
let _3 = (Parsing.peek_val __caml_parser_env 0 : 'expr1) in
Obj.repr(
-# 80 "parser.mly"
- ( Case (_1, None, _3) )
-# 610 "parser.ml"
+# 77 "parser.mly"
+ ( Case {patt = _1; guard = None; body = _3} )
+# 603 "parser.ml"
: 'case))
; (fun __caml_parser_env ->
- let _1 = (Parsing.peek_val __caml_parser_env 2 : 'expr1) in
- let _3 = (Parsing.peek_val __caml_parser_env 0 : 'expr1_list) in
+ let _1 = (Parsing.peek_val __caml_parser_env 2 : 'expr2) in
+ let _3 = (Parsing.peek_val __caml_parser_env 0 : 'annot_list) in
Obj.repr(
-# 83 "parser.mly"
+# 80 "parser.mly"
( _1 :: _3 )
-# 618 "parser.ml"
- : 'expr1_list))
+# 611 "parser.ml"
+ : 'annot_list))
; (fun __caml_parser_env ->
- let _1 = (Parsing.peek_val __caml_parser_env 0 : 'expr1) in
+ let _1 = (Parsing.peek_val __caml_parser_env 0 : 'expr2) in
Obj.repr(
-# 84 "parser.mly"
+# 81 "parser.mly"
( [_1] )
-# 625 "parser.ml"
- : 'expr1_list))
+# 618 "parser.ml"
+ : 'annot_list))
; (fun __caml_parser_env ->
Obj.repr(
+# 82 "parser.mly"
+ ( [] )
+# 624 "parser.ml"
+ : 'annot_list))
+; (fun __caml_parser_env ->
+ let _1 = (Parsing.peek_val __caml_parser_env 1 : 'expr7) in
+ let _2 = (Parsing.peek_val __caml_parser_env 0 : 'expr7_apposition) in
+ Obj.repr(
# 85 "parser.mly"
+ ( _1 :: _2 )
+# 632 "parser.ml"
+ : 'expr7_apposition))
+; (fun __caml_parser_env ->
+ Obj.repr(
+# 86 "parser.mly"
( [] )
-# 631 "parser.ml"
- : 'expr1_list))
+# 638 "parser.ml"
+ : 'expr7_apposition))
; (fun __caml_parser_env ->
- let _2 = (Parsing.peek_val __caml_parser_env 3 : 'expr1) in
- let _4 = (Parsing.peek_val __caml_parser_env 1 : 'expr1_list) in
+ let _1 = (Parsing.peek_val __caml_parser_env 2 : 'variant_def) in
+ let _3 = (Parsing.peek_val __caml_parser_env 0 : 'variant_def_list) in
Obj.repr(
-# 88 "parser.mly"
- ( _2 :: _4 )
-# 639 "parser.ml"
- : 'tuple))
+# 89 "parser.mly"
+ ( _1 :: _3 )
+# 646 "parser.ml"
+ : 'variant_def_list))
; (fun __caml_parser_env ->
- let _1 = (Parsing.peek_val __caml_parser_env 2 : 'variant) in
- let _3 = (Parsing.peek_val __caml_parser_env 0 : 'variants) in
+ let _1 = (Parsing.peek_val __caml_parser_env 0 : 'variant_def) in
Obj.repr(
-# 91 "parser.mly"
- ( _1 :: _3 )
-# 647 "parser.ml"
- : 'variants))
+# 90 "parser.mly"
+ ( [_1] )
+# 653 "parser.ml"
+ : 'variant_def_list))
; (fun __caml_parser_env ->
- let _1 = (Parsing.peek_val __caml_parser_env 0 : 'variant) in
Obj.repr(
-# 92 "parser.mly"
- ( [_1] )
-# 654 "parser.ml"
- : 'variants))
+# 91 "parser.mly"
+ ( [] )
+# 659 "parser.ml"
+ : 'variant_def_list))
; (fun __caml_parser_env ->
+ let _2 = (Parsing.peek_val __caml_parser_env 1 : Common.ident) in
+ let _3 = (Parsing.peek_val __caml_parser_env 0 : 'annot_list) in
Obj.repr(
# 93 "parser.mly"
+ ( (_2, _3) )
+# 667 "parser.ml"
+ : 'variant_def))
+; (fun __caml_parser_env ->
+ let _1 = (Parsing.peek_val __caml_parser_env 2 : 'field_def) in
+ let _3 = (Parsing.peek_val __caml_parser_env 0 : 'field_def_list) in
+ Obj.repr(
+# 96 "parser.mly"
+ ( _1 :: _3 )
+# 675 "parser.ml"
+ : 'field_def_list))
+; (fun __caml_parser_env ->
+ let _1 = (Parsing.peek_val __caml_parser_env 0 : 'field_def) in
+ Obj.repr(
+# 97 "parser.mly"
+ ( [_1] )
+# 682 "parser.ml"
+ : 'field_def_list))
+; (fun __caml_parser_env ->
+ Obj.repr(
+# 98 "parser.mly"
( [] )
-# 660 "parser.ml"
- : 'variants))
+# 688 "parser.ml"
+ : 'field_def_list))
; (fun __caml_parser_env ->
- let _2 = (Parsing.peek_val __caml_parser_env 1 : Surf.ident) in
+ let _1 = (Parsing.peek_val __caml_parser_env 2 : Common.ident) in
+ let _3 = (Parsing.peek_val __caml_parser_env 0 : 'expr2) in
+ Obj.repr(
+# 100 "parser.mly"
+ ( (_1, _3) )
+# 696 "parser.ml"
+ : 'field_def))
+; (fun __caml_parser_env ->
+ let _2 = (Parsing.peek_val __caml_parser_env 3 : 'expr1) in
+ let _4 = (Parsing.peek_val __caml_parser_env 1 : 'expr1_list) in
+ Obj.repr(
+# 103 "parser.mly"
+ ( _2 :: _4 )
+# 704 "parser.ml"
+ : 'tuple))
+; (fun __caml_parser_env ->
+ let _1 = (Parsing.peek_val __caml_parser_env 2 : 'expr1) in
let _3 = (Parsing.peek_val __caml_parser_env 0 : 'expr1_list) in
Obj.repr(
-# 95 "parser.mly"
- ( Variant (_2, _3) )
-# 668 "parser.ml"
- : 'variant))
+# 105 "parser.mly"
+ ( _1 :: _3 )
+# 712 "parser.ml"
+ : 'expr1_list))
+; (fun __caml_parser_env ->
+ let _1 = (Parsing.peek_val __caml_parser_env 0 : 'expr1) in
+ Obj.repr(
+# 106 "parser.mly"
+ ( [_1] )
+# 719 "parser.ml"
+ : 'expr1_list))
+; (fun __caml_parser_env ->
+ Obj.repr(
+# 107 "parser.mly"
+ ( [] )
+# 725 "parser.ml"
+ : 'expr1_list))
; (fun __caml_parser_env ->
let _1 = (Parsing.peek_val __caml_parser_env 2 : 'field) in
- let _3 = (Parsing.peek_val __caml_parser_env 0 : 'fields) in
+ let _3 = (Parsing.peek_val __caml_parser_env 0 : 'field_list) in
Obj.repr(
-# 98 "parser.mly"
+# 110 "parser.mly"
( _1 :: _3 )
-# 676 "parser.ml"
- : 'fields))
+# 733 "parser.ml"
+ : 'field_list))
; (fun __caml_parser_env ->
let _1 = (Parsing.peek_val __caml_parser_env 0 : 'field) in
Obj.repr(
-# 99 "parser.mly"
+# 111 "parser.mly"
( [_1] )
-# 683 "parser.ml"
- : 'fields))
+# 740 "parser.ml"
+ : 'field_list))
; (fun __caml_parser_env ->
Obj.repr(
-# 100 "parser.mly"
+# 112 "parser.mly"
( [] )
-# 689 "parser.ml"
- : 'fields))
+# 746 "parser.ml"
+ : 'field_list))
; (fun __caml_parser_env ->
- let _1 = (Parsing.peek_val __caml_parser_env 2 : 'expr1) in
+ let _1 = (Parsing.peek_val __caml_parser_env 2 : Common.ident) in
let _3 = (Parsing.peek_val __caml_parser_env 0 : 'expr1) in
Obj.repr(
-# 102 "parser.mly"
- ( Field (_1, _3) )
-# 697 "parser.ml"
+# 114 "parser.mly"
+ ( (_1, _3) )
+# 754 "parser.ml"
: 'field))
(* Entry expr0 *)
; (fun __caml_parser_env -> raise (Parsing.YYexit (Parsing.peek_val __caml_parser_env 0)))
@@ -716,5 +773,5 @@ let yytables =
Parsing.names_const=yynames_const;
Parsing.names_block=yynames_block }
let expr0 (lexfun : Lexing.lexbuf -> token) (lexbuf : Lexing.lexbuf) =
- (Parsing.yyparse yytables 1 lexfun lexbuf : Surf.expr)
+ (Parsing.yyparse yytables 1 lexfun lexbuf : Concrete.expr)
;;
diff --git a/parser.mly b/parser.mly
@@ -1,5 +1,5 @@
%{
-open Surf
+open Concrete
%}
%token EOF
@@ -13,11 +13,11 @@ open Surf
%token IF THEN ELSE
%token IFF DO
%token FN
-%token <Surf.ident> IDENT
+%token <Common.ident> IDENT
%token <Z.t> INT
%start expr0
-%type <Surf.expr> expr0
+%type <Concrete.expr> expr0
%nonassoc PREC_EXPR4
%nonassoc PREC_TUPLE
@@ -33,9 +33,9 @@ expr1: (* Control flow *)
| expr2 MATCH LBRACE cases RBRACE { Match($1, $4) }
| IF expr1 THEN expr1 ELSE expr1 { If ($2, $4, $6) }
| IFF expr1 DO expr1 { Iff ($2, $4) }
- | FN expr1_list SINGLE_ARROW expr1 { Fn ($2, $4) }
+ | FN annot_list SINGLE_ARROW expr1 { Fn ($2, $4) }
| expr2 { $1 }
-expr2: (* Type annotations (right-associative) *)
+expr2: (* Type annotations (right-associative); lowest prec for patterns *)
| expr3 COLON expr2 { Annot($1, $3) }
| expr3 { $1 }
expr3: (* Function arrow (right-associative) *)
@@ -50,7 +50,7 @@ expr5:
| expr6 { $1 }
expr6:
| expr7 expr7 expr7_apposition { App ($1, $2 :: $3) }
- | AT IDENT expr7_apposition { Cons ($2, $3) }
+ | AT IDENT expr7_apposition { Variant ($2, $3) }
| expr7 { $1 }
expr7:
| expr7 DOT IDENT { Access ($1, $3) }
@@ -58,47 +58,59 @@ expr7:
| expr7 EXCLAM { Deref $1 }
| expr8 { $1 }
expr8:
- | IDENT { Ident $1 }
+ | IDENT { if $1 = "_" then Underscore else Ident $1 }
| INT { Int $1 }
- | HASH_LBRACK variants RBRACK { VariantType $2 }
- | HASH_LPAREN expr1_list RPAREN { TupleType $2 }
- | HASH_LBRACE expr1_list RBRACE { RecordType $2 }
+ | HASH_LBRACK variant_def_list RBRACK { VariantType $2 }
+ | HASH_LPAREN annot_list RPAREN { TupleType $2 }
+ | HASH_LBRACE field_def_list RBRACE { RecordType $2 }
| tuple %prec PREC_TUPLE { Tuple $1 }
- | LBRACE fields RBRACE { Record $2 }
+ | LBRACE field_list RBRACE { Record $2 }
+ | LPAREN RPAREN { Unit }
| LPAREN expr0 RPAREN { $2 }
+cases: (* Has optional trailing semicolon *)
+ | case SEMICOLON cases { $1 :: $3 }
+ | case { [$1] }
+ | { [] }
+case:
+ | expr2 IF expr1 DOUBLE_ARROW expr1 { Case {patt = $1; guard = Some ($3); body = $5} }
+ | expr2 DOUBLE_ARROW expr1 { Case {patt = $1; guard = None; body = $3} }
+
+annot_list: (* Has optional trailing comma *)
+ | expr2 COMMA annot_list { $1 :: $3 }
+ | expr2 { [$1] }
+ | { [] }
+
expr7_apposition:
| expr7 expr7_apposition { $1 :: $2 }
| { [] }
-cases: (* Optional trailing semicolon *)
- | case SEMICOLON cases { $1 :: $3 }
- | case { [$1] }
+variant_def_list: (* Has optional trailing semicolon *)
+ | variant_def SEMICOLON variant_def_list { $1 :: $3 }
+ | variant_def { [$1] }
| { [] }
-case:
- | expr2 IF expr1 DOUBLE_ARROW expr1 { Case ($1, Some ($3), $5) }
- | expr2 DOUBLE_ARROW expr1 { Case ($1, None, $3) }
+variant_def:
+ | AT IDENT annot_list { ($2, $3) }
-expr1_list: (* Optional trailing comma *)
- | expr1 COMMA expr1_list { $1 :: $3 }
- | expr1 { [$1] }
+field_def_list: (* Has optional trailing comma *)
+ | field_def COMMA field_def_list { $1 :: $3 }
+ | field_def { [$1] }
| { [] }
+field_def:
+ | IDENT COLON expr2 { ($1, $3) }
tuple: (* Nonempty; trailing comma mandatory for 1-tuples *)
| LPAREN expr1 COMMA expr1_list RPAREN { $2 :: $4 }
-
-variants: (* Optional trailing semicolon *)
- | variant SEMICOLON variants { $1 :: $3 }
- | variant { [$1] }
+expr1_list: (* Has optional trailing comma *)
+ | expr1 COMMA expr1_list { $1 :: $3 }
+ | expr1 { [$1] }
| { [] }
-variant:
- | AT IDENT expr1_list { Variant ($2, $3) }
-fields: (* Optional trailing semicolon *)
- | field SEMICOLON fields { $1 :: $3 }
+field_list: (* Has optional trailing comma *)
+ | field COMMA field_list { $1 :: $3 }
| field { [$1] }
| { [] }
field:
- | expr1 COLON_EQ expr1 { Field ($1, $3) }
+ | IDENT COLON_EQ expr1 { ($1, $3) }
%%
diff --git a/raw.ml b/raw.ml
@@ -1,52 +0,0 @@
-open Common
-
-type expr =
-| Let of expr * expr * expr
-| Seq of expr * expr
-| Match of expr * case list
-| If of expr * expr * expr
-| Iff of expr * expr
-| Fn of expr list * expr
-| Annot of expr * expr
-| FnType of expr list * expr
-| Add of expr * expr
-| Mul of expr * expr
-| App of expr * expr list
-| Cons of ident * expr_list
-| Access of expr * ident
-| Index of expr * expr
-| Deref of expr
-| Ident of ident
-| Int of Z.t
-| VariantType of variant list
-| TupleType of expr list
-| RecordType of expr list
-| Tuple of expr list
-| Record of field list
-and case = Case of {patt: expr; guard: expr option; body: expr}
-and variant = Variant of ident * expr list
-and field = Field of expr * expr
-
-let rec string_of_expr m e =
- let sp = string_of_patt in
- let se = string_of_expr in
- let (c, s) = match e with
- | Let (p, a, b) -> (0, "let " ^ sp 0 p ^ " = " ^ se 1 a ^ "; " ^ se 0 b)
- | If (c, t, f) -> (0, "if " ^ se 1 c ^ " then " ^ se 1 t ^ " else " ^ se 1 f)
- | Fn (p, e) -> (1, "@(" ^ sp 0 p ^ ") -> " ^ se 1 e)
- | Pi (p, e) -> (1, "#(" ^ sp 0 p ^ ") -> " ^ se 1 e)
- | Hint (a, b) -> (1, se 2 a ^ " : " ^ se 1 b)
- | Plus (a, b) -> (2, se 2 a ^ " + " ^ se 3 b)
- | Asterisk (a, b) -> (3, se 3 a ^ " * " ^ se 4 b)
- | Apposition (a, b) -> (4, se 4 a ^ " " ^ se 5 b)
- | Var x -> (5, x)
- | Int z -> (5, Z.to_string z) in
- if c < m then "(" ^ s ^ ")" else s
-
-and string_of_patt m p =
- let sp = string_of_patt in
- let se = string_of_expr in
- let (c, s) = match p with
- | Annot (p, e) -> (0, sp 1 p ^ " : " ^ se 1 e)
- | Wild x -> (1, x) in
- if c < m then "(" ^ s ^ ")" else s