Skip to content

Commit

Permalink
Merge pull request #68 from gfngfn/fix-associativity-of-arithmetic-op…
Browse files Browse the repository at this point in the history
…erators

Fix associativity of arithmetic operators
  • Loading branch information
gfngfn authored Dec 12, 2021
2 parents 4e048cc + 5b11d37 commit e41e4c5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -565,13 +565,13 @@ exprcons:
| e=exprplus { e }
;
exprplus:
| e1=exprtimes; op=BINOP_PLUS; e2=exprplus { binary e1 op e2 }
| e1=exprtimes; op=BINOP_MINUS; e2=exprplus { binary e1 op e2 }
| e1=exprplus; op=BINOP_PLUS; e2=exprtimes { binary e1 op e2 }
| e1=exprplus; op=BINOP_MINUS; e2=exprtimes { binary e1 op e2 }
| e=exprtimes { e }
;
exprtimes:
| e1=exprapp; op=BINOP_TIMES; e2=exprtimes { binary e1 op e2 }
| e1=exprapp; op=BINOP_DIVIDES; e2=exprtimes { binary e1 op e2 }
| e1=exprtimes; op=BINOP_TIMES; e2=exprapp { binary e1 op e2 }
| e1=exprtimes; op=BINOP_DIVIDES; e2=exprapp { binary e1 op e2 }
| e=exprapp { e }
;
exprapp:
Expand Down
4 changes: 4 additions & 0 deletions test/pass/arith.sest
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ module Arith = struct
val main(_) =
let 13 = 3 * 4 + 1 in
let 13 = 1 + 3 * 4 in
let 1 = 4 / 2 / 2 in
let 8 = 8 * 2 / 2 in
let 14 = 57 - 42 - 1 in
let 16 = 57 - 42 + 1 in
{}

end

0 comments on commit e41e4c5

Please sign in to comment.