Ast.OperatorSourceOperators
This module allows adding new operators to the extensible Mopsa AST.
To add a new operator, first extend type operator with a new variant constructor. For instance,
type operator += O_eqadds a new constructor for an equality operator.
After adding the new variant, register it by declaring a compare and a print function:
let () = register_operator {
compare = (fun next o1 o2 ->
match o1, o2 with
| O_eq, O_eq -> 0
| _ -> next o1 o2
);
print = (fun next -> function
| O_eq -> Format.pp_print_string fmt "=="
| _ -> next fmt o
);
}Note that the comparison function can be reduced in this cast to compare = (fun next -> next) because the operator O_eq doesn't have a structure and the pervasive compare used by default is sufficient.
Any registered constant can be compared and printed with functions compare_constant and pp_constant.
Extensible type of operators
register_operator info registers a new operator by registering its compare function info.compare and pretty-printer info.print
Register a comparison function for operators
Register a pretty-printer for operators
type operator += | O_eqequality ==
*)| O_neinequality !=
*)| O_ltless than <
*)| O_leless or equal <=
*)| O_gtgreater than >
*)| O_gegreater or equal >=
*)| O_log_notlogical negation
*)| O_log_orlogical disjunction ||
*)| O_log_andlogical conjunction &&
*)| O_log_xorlogical strict disjonction xor
*)| O_casttype cast
*)Common operators