type token = Kwd of string | Ident of string | Int of int | Float of float | String of string | Char of char
value make_lexer: string list -> (char stream -> token stream)
let lexer = make_lexer ["+";"-";"*";"/";"let";"="; "("; ")"]
The associated parser would be a function from token stream to, for instance, int, and would have rules such as:
let parse_expr = function [< 'Int n >] -> n | [< 'Kwd "("; parse_expr n; 'Kwd ")" >] -> n | [< parse_expr n1; (parse_remainder n1) n2 >] -> n2 and parse_remainder n1 = function [< 'Kwd "+"; parse_expr n2 >] -> n1+n2 | ...