2022-01-10 01:31:47 +09:00
|
|
|
type t =
|
2022-01-21 02:17:34 +09:00
|
|
|
| Value of Ast.Value.t
|
2022-01-10 01:31:47 +09:00
|
|
|
| Ident of string
|
|
|
|
| Plus
|
|
|
|
| Minus
|
|
|
|
| Asterisk
|
|
|
|
| Slash
|
2022-01-13 01:13:41 +09:00
|
|
|
| Carret
|
|
|
|
| Percent
|
2022-01-10 01:31:47 +09:00
|
|
|
| LParen
|
|
|
|
| RParen
|
2022-01-21 00:17:01 +09:00
|
|
|
| Equal
|
2022-01-10 01:31:47 +09:00
|
|
|
|
2022-01-17 15:17:18 +09:00
|
|
|
let tokens = ref [
|
|
|
|
"+", Plus;
|
|
|
|
"-", Minus;
|
|
|
|
"*", Asterisk;
|
|
|
|
"/", Slash;
|
|
|
|
"^", Carret;
|
|
|
|
"%", Percent;
|
|
|
|
"(", LParen;
|
|
|
|
")", RParen;
|
2022-01-21 00:17:01 +09:00
|
|
|
"=", Equal;
|
2022-01-17 15:17:18 +09:00
|
|
|
]
|
2022-01-10 01:31:47 +09:00
|
|
|
|
|
|
|
let to_string = function
|
2022-01-21 02:17:34 +09:00
|
|
|
| Value v -> Ast.Value.to_string v
|
2022-01-10 01:31:47 +09:00
|
|
|
| Ident s -> s
|
2022-01-17 15:17:18 +09:00
|
|
|
| t ->
|
|
|
|
begin match List.find_opt (fun (_, tok) -> t = tok) !tokens with
|
|
|
|
| None -> failwith "Token.to_string"
|
|
|
|
| Some (s, _) -> s
|
|
|
|
end
|