Skip to content

Commit

Permalink
Several operator precedence improvements as well as a generator for b…
Browse files Browse the repository at this point in the history
…inary expressions
  • Loading branch information
7h3kk1d committed Dec 16, 2024
1 parent 428faaa commit 956fb32
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
6 changes: 6 additions & 0 deletions src/haz3lmenhir/AST.re
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@ let rec gen_exp_sized = (n: int): QCheck.Gen.t(exp) =>
arb_constructor_ident.gen,
gen_typ_sized(n - 1),
),
Gen.map3(
(op, e1, e2) => BinExp(e1, op, e2),
gen_binOp,
self((n - 1) / 2),
self((n - 1) / 2),
),
]);
}
},
Expand Down
17 changes: 6 additions & 11 deletions src/haz3lmenhir/Parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,17 @@ open AST

%left COLON
%right DASH_ARROW
%left L_NOT L_AND L_OR // TODO Check with Milan. I moved this to make tests pass.
%right L_OR // TODO Check with Milan. I moved this to make tests pass.
%right L_AND
%right L_NOT

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

%left GREATER_THAN LESS_THAN DOUBLE_EQUAL NOT_EQUAL LESS_THAN_EQUAL GREATER_THAN_EQUAL NOT_EQUAL_FLOAT LESS_THAN_FLOAT LESS_THAN_EQUAL_FLOAT GREATER_THAN_FLOAT GREATER_THAN_EQUAL_FLOAT DOUBLE_EQUAL_FLOAT STRING_EQUAL
%right STRING_CONCAT
%left PLUS MINUS
%left DIVIDE TIMES
%right POWER

%left GREATER_THAN LESS_THAN

(* End of int op precedences *)

(* Float op precedences *)

%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
Expand All @@ -153,7 +149,6 @@ open AST



%left STRING_CONCAT STRING_EQUAL

%type <AST.exp> exp
%type <AST.sumtype> sumTyp
Expand Down
6 changes: 6 additions & 0 deletions test/Test_Menhir.re
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,17 @@ let qcheck_menhir_maketerm_equivalent_test =
);

let serialized = Printer.of_segment(~holes=Some("?"), segment);
print_endline("Serialized: " ++ serialized);
let make_term_parsed = make_term_parse(serialized);
let menhir_parsed = Haz3lmenhir.Interface.parse_program(serialized);
let menhir_parsed_converted =
Haz3lmenhir.Conversion.Exp.of_menhir_ast(menhir_parsed);

print_endline("MakeTerm: " ++ DHExp.show(make_term_parsed));
print_endline(
"Menhir parsed: " ++ DHExp.show(menhir_parsed_converted),
);

Haz3lcore.DHExp.fast_equal(make_term_parsed, menhir_parsed_converted);
},
);
Expand Down

0 comments on commit 956fb32

Please sign in to comment.