Skip to content

Commit

Permalink
🐛 Fix parser conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeta611 committed Sep 23, 2024
1 parent 920f097 commit 871451e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
1 change: 0 additions & 1 deletion lib/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
11 changes: 5 additions & 6 deletions lib/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -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> INT
%token <string> ID
%token <string> STRING
%token RECORD DOT ASSIGN
%token RECORD ASSIGN
%token VIEW
%token FUN LET STT IN EFF
%token IF THEN ELSE
Expand All @@ -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
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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 }

0 comments on commit 871451e

Please sign in to comment.