diff --git a/lib/lexer.mll b/lib/lexer.mll index e706b28..e426f07 100644 --- a/lib/lexer.mll +++ b/lib/lexer.mll @@ -59,7 +59,6 @@ rule read = | id as s { match Hashtbl.find_opt keywords s with Some s -> s | None -> ID s } | str as s { STRING (String.sub s 1 (String.length s - 2) |> unescape_string) } | "{}" { RECORD } - | '.' { DOT } | ":=" { ASSIGN } | '#' { comment lexbuf } | "->" { RARROW } diff --git a/lib/parser.mly b/lib/parser.mly index efe821c..727e148 100644 --- a/lib/parser.mly +++ b/lib/parser.mly @@ -11,14 +11,13 @@ let rec label_stts_prog = function and label_stts_expr label = function | Stt s -> Stt { s with label; body = label_stts_expr (label + 1) s.body } | e -> e - %} %token UNIT TRUE FALSE %token INT %token ID %token STRING -%token RECORD DOT ASSIGN +%token RECORD ASSIGN %token VIEW %token FUN LET STT IN EFF %token IF THEN ELSE @@ -32,10 +31,10 @@ and label_stts_expr label = function %nonassoc RARROW %nonassoc IN %right SEMI -%nonassoc ASSIGN %nonassoc EFF %nonassoc THEN /* below ELSE (if ... then ...) */ %nonassoc ELSE /* (if ... then ... else ...) */ +%nonassoc ASSIGN %right OR %right AND %left EQ LT GT NE LE GE @@ -79,9 +78,8 @@ expr_: | op = uop; expr_ = expr_ %prec prec_unary { Ex (Uop { op; arg = hook_free_exn expr_ }) } | left = expr_; op = bop; right = expr_ { Ex (Bop { op; left = hook_free_exn left; right = hook_free_exn right }) } - | RECORD { Ex (Alloc) } - | obj = expr_; LBRACK; index = expr_; RBRACK { Ex (Get { obj = hook_free_exn obj; idx = hook_free_exn index }) } - | obj = expr_; LBRACK; index = expr_; RBRACK; ASSIGN; value = expr_ + | obj = apply; LBRACK; index = expr_; RBRACK { Ex (Get { obj = hook_free_exn obj; idx = hook_free_exn index }) } + | obj = apply; LBRACK; index = expr_; RBRACK; ASSIGN; value = expr_ { Ex (Set { obj = hook_free_exn obj; idx = hook_free_exn index; value = hook_free_exn value }) } %inline uop: | NOT { Not } @@ -109,6 +107,7 @@ atom: | n = INT { Ex (Const (Int n)) } | s = STRING { Ex (Const (String s)) } | var = var { Ex (Var var) } + | RECORD { Ex (Alloc) } | LPAREN; e = expr_; RPAREN { e } var: | x = ID { x }