Add associativity table
This commit is contained in:
parent
856c2b359e
commit
7fd3917572
1 changed files with 14 additions and 3 deletions
17
parser.ml
17
parser.ml
|
@ -29,9 +29,20 @@ let precedence = [
|
|||
let precedence_of op =
|
||||
Hashtbl.find precedence op
|
||||
|
||||
let op_is_right_to_left = function
|
||||
| Exp -> true
|
||||
| _ -> false
|
||||
type associativity =
|
||||
| Left_to_right
|
||||
| Right_to_left
|
||||
|
||||
let oper_assoc = [
|
||||
Exp, Right_to_left;
|
||||
] |> List.to_seq |> Hashtbl.of_seq
|
||||
|
||||
let op_is_right_to_left op =
|
||||
let a =
|
||||
Hashtbl.find_opt oper_assoc op
|
||||
|> Option.value ~default: Left_to_right
|
||||
in
|
||||
a = Right_to_left
|
||||
|
||||
let operators = [
|
||||
Token.Plus, Add;
|
||||
|
|
Loading…
Add table
Reference in a new issue