Skip to content

Commit 946cf0c

Browse files
committed
More expressive on the ast/compiler
1 parent f9ce92d commit 946cf0c

File tree

4 files changed

+33
-33
lines changed

4 files changed

+33
-33
lines changed

source/Ast.ml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ type builtin = Add | Abs [@@deriving show { with_path = false }]
99

1010
type op =
1111
| Add
12-
| Sub
13-
| Mult
14-
| Div
15-
| Eq
16-
| Neq
17-
| Gt (* > *)
18-
| St (* < *)
19-
| Ge (* >=*)
20-
| Se (* <= *)
12+
| Subtract
13+
| Multiply
14+
| Divide
15+
| Equal
16+
| Not_equal
17+
| Greater_than
18+
| Less_than
19+
| Greater_than_or_equal
20+
| Less_than_or_equal
2121
| And
2222
| Or
2323
[@@deriving show { with_path = false }]

source/Compiler.ml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,14 @@ module Operators = struct
138138
let lte = compare "<=" ( <= )
139139
let and_ = condition "and" ( && )
140140
let or_ = condition "or" ( || )
141-
let eq l r = Output.return (`Bool (l = r))
142-
let notEq l r = Output.return (`Bool (l <> r))
141+
let equal l r = Output.return (`Bool (l = r))
142+
let not_equal l r = Output.return (`Bool (l <> r))
143143

144144
(* Since + is used to concat strings, objects, lists, we don't use apply_op *)
145145
let add = add "+"
146-
let sub = apply_op "-" (fun l r -> l -. r)
147-
let mult = apply_op "*" (fun l r -> l *. r)
148-
let div = apply_op "/" (fun l r -> l /. r)
146+
let subtract = apply_op "-" (fun l r -> l -. r)
147+
let multiply = apply_op "*" (fun l r -> l *. r)
148+
let divide = apply_op "/" (fun l r -> l /. r)
149149
end
150150

151151
let keys (json : Json.t) =
@@ -341,15 +341,15 @@ let rec compile expression json : (Json.t list, string) result =
341341
| Operation (left, op, right) -> (
342342
match op with
343343
| Add -> operation left right Operators.add json
344-
| Sub -> operation left right Operators.sub json
345-
| Mult -> operation left right Operators.mult json
346-
| Div -> operation left right Operators.div json
347-
| Gt -> operation left right Operators.gt json
348-
| Ge -> operation left right Operators.gte json
349-
| St -> operation left right Operators.lt json
350-
| Se -> operation left right Operators.lte json
351-
| Eq -> operation left right Operators.eq json
352-
| Neq -> operation left right Operators.notEq json
344+
| Subtract -> operation left right Operators.subtract json
345+
| Multiply -> operation left right Operators.multiply json
346+
| Divide -> operation left right Operators.divide json
347+
| Greater_than -> operation left right Operators.gt json
348+
| Greater_than_or_equal -> operation left right Operators.gte json
349+
| Less_than -> operation left right Operators.lt json
350+
| Less_than_or_equal -> operation left right Operators.lte json
351+
| Equal -> operation left right Operators.equal json
352+
| Not_equal -> operation left right Operators.not_equal json
353353
| And -> operation left right Operators.and_ json
354354
| Or -> operation left right Operators.or_ json)
355355
| Literal literal -> (

source/Parser.mly

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,16 @@ sequence_expr:
8383
{ e }
8484

8585
%inline operator:
86-
| SUB {Sub}
86+
| SUB {Subtract}
8787
| ADD {Add}
88-
| MULT {Mult}
89-
| DIV {Div}
90-
| EQUAL {Eq}
91-
| NOT_EQUAL {Neq}
92-
| GREATER {Gt}
93-
| LOWER {St}
94-
| GREATER_EQUAL {Ge}
95-
| LOWER_EQUAL {Se}
88+
| MULT {Multiply}
89+
| DIV {Divide}
90+
| EQUAL {Equal}
91+
| NOT_EQUAL {Not_equal}
92+
| GREATER {Greater_than}
93+
| LOWER {Less_than}
94+
| GREATER_EQUAL {Greater_than_or_equal}
95+
| LOWER_EQUAL {Less_than_or_equal}
9696
| AND {And}
9797
| OR {Or}
9898

test/Test_parse.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ let tests =
4444
(Operation
4545
( Literal (Number 1.),
4646
Add,
47-
Operation (Literal (Number 2.), Mult, Literal (Number 3.)) ));
47+
Operation (Literal (Number 2.), Multiply, Literal (Number 3.)) ));
4848
case "[1, 2]" (List [ Literal (Number 1.); Literal (Number 2.) ]);
4949
case "select(true)" (Select (Literal (Bool true)));
5050
case "[1][0]" (Pipe (List [ Literal (Number 1.) ], Index 0));

0 commit comments

Comments
 (0)