Skip to content

Commit

Permalink
Fix integer and float precedences
Browse files Browse the repository at this point in the history
  • Loading branch information
7h3kk1d committed Dec 2, 2024
1 parent f202efd commit 115d4e2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/haz3lmenhir/Parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,8 @@ open AST

(* Int op precedences *)
%left DOUBLE_EQUAL NOT_EQUAL LESS_THAN_EQUAL GREATER_THAN_EQUAL

%left PLUS MINUS
%left DIVIDE TIMES
%left PLUS MINUS
%right DIVIDE TIMES
%right POWER

%left GREATER_THAN LESS_THAN
Expand All @@ -132,7 +131,7 @@ open AST
%left DOUBLE_EQUAL_FLOAT NOT_EQUAL_FLOAT LESS_THAN_FLOAT LESS_THAN_EQUAL_FLOAT GREATER_THAN_FLOAT GREATER_THAN_EQUAL_FLOAT

%left PLUS_FLOAT MINUS_FLOAT
%left TIMES_FLOAT DIVIDE_FLOAT
%right TIMES_FLOAT DIVIDE_FLOAT
%right POWER_FLOAT

%left OPEN_CURLY
Expand Down
22 changes: 22 additions & 0 deletions test/Test_Menhir.re
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,28 @@ let tests = [
|> Exp.fresh,
"[1, 2] @ [3, 4]",
),
parser_test(
"times and divide precendence",
BinOp(
Int(Times),
Int(1) |> Exp.fresh,
BinOp(Int(Divide), Int(2) |> Exp.fresh, Int(3) |> Exp.fresh)
|> Exp.fresh,
)
|> Exp.fresh,
"1 * 2 / 3",
),
parser_test(
"plus and minus precendence",
BinOp(
Int(Plus),
BinOp(Int(Minus), Int(1) |> Exp.fresh, Int(2) |> Exp.fresh)
|> Exp.fresh,
Int(3) |> Exp.fresh,
)
|> Exp.fresh,
"1 - 2 + 3",
),
parser_test(
"Integer Ops",
BinOp(
Expand Down

0 comments on commit 115d4e2

Please sign in to comment.