module CS334 open Combinator type Expr = | Terms of Term list and Term = | AAA | BBB | Brace of Expr let expr,exprImpl = recparser() let aaa = pstr "aaa" |>> (fun _ -> AAA) let bbb = pstr "bbb" |>> (fun _ -> BBB) let brace = pbetween (pchar '{') expr (pchar '}') |>> Brace let term = aaa <|> bbb <|> brace exprImpl := pmany1 term |>> Terms let grammar = pleft expr peof let parse (input: string) : Expr option = let i = prepare input match grammar i with | Success (ast,_) -> Some ast | Failure _ -> None