anchor.diff:  (* The basic lexical classes: identifiers, strings and reserved words.       *)
   (* ------------------------------------------------------------------------- *)
   
  -type lexcode =
  +type lexcode = 
       | Ident of string
       | Resword of string
   
  
positive.code: (* Type and term parsers.                                                    *)
  (* ------------------------------------------------------------------------- *)
  
  let parse_type s =
    let pty,l = (parse_pretype << lex << explode) s
    if l = [] then type_of_pretype pty
    else failwith "Unparsed input following type"
  
  let parse_term s =
    let ptm,l = (parse_preterm << lex << explode) s
    if l = [] then (term_of_preterm << (retypecheck [])) ptm
    else failwith "Unparsed input following term"
  
  
  
negative.code:        Combp(Combp(Combp(Varp("_GUARDED_PATTERN",dpty),pmk_geq pat x), hd guards), pmk_geq res y)
      Absp(x,Absp(y,itlist (curry pmk_exists) vs bod))
    let pretype = parse_pretype
    let rec string inp = 
        match inp with
        | Ident s :: rst when String.length s >= 2 && String.sub s 0 1 = "\"" && String.sub s (String.length s - 1) 1 = "\"" -> 
            String.sub s 1 (String.length s - 2), rst
        | _ -> raise Noparse
    
    and singleton1 x = [x]
    
    and lmk_ite(((((_, b), _), l), _), r) = Combp(Combp(Combp(Varp("COND", dpty), b), l), r)
    
    and lmk_typed = 
        function 
        | (p, []) -> p
        | (p, [ty]) -> Typing(p, ty)
        | _ -> fail()
    
    and lmk_let(((_, bnds), _), ptm) = pmk_let(bnds, ptm)
    
    and lmk_binder((((s, h), t), _), p) = pmk_binder(s, h :: t, p)
    
    and lmk_setenum(l, _) = pmk_set_enum l
    
    and lmk_setabs(((l, _), r), _) = pmk_setabs(l, r)
    
    and lmk_setcompr(((((f, _), vs), _), b), _) = pmk_setcompr(f, pfrees vs [], b)
    
    and lmk_decimal((_, l0), ropt) = 
        let l, r = 
            if ropt = [] then l0, "1"
            else 
                let r0 = hd ropt
                let n_l = num_of_string l0
                let n_r = num_of_string r0
                let n_d = power_num (Int 10) (Int(String.length r0))
                let n_n = n_l */ n_d +/ n_r
                string_of_num n_n, string_of_num n_d
        Combp(Combp(Varp("DECIMAL", dpty), Varp(l, dpty)), Varp(r, dpty))
    
    and lmk_univ((_, pty), _) = 
        Typing(Varp("UNIV", dpty), Ptycon("fun", [pty;
                                                  Ptycon("bool", [])]))
    
    and any_identifier = 
        function 
        | ((Ident s) :: rest) -> s, rest
        | _ -> raise Noparse
    
    and identifier = 
        function 
        | ((Ident s) :: rest) -> 
            if can get_infix_status s || is_prefix s || parses_as_binder s then raise Noparse
            else s, rest
        | _ -> raise Noparse
    
    and binder = 
        function 
        | ((Ident s) :: rest) -> 
            if parses_as_binder s then s, rest
            else raise Noparse
        | _ -> raise Noparse
    
    and pre_fix = 
        function 
        | ((Ident s) :: rest) -> 
            if is_prefix s then s, rest
            else raise Noparse
        | _ -> raise Noparse
    
    let rec preterm i = mk_precedence (infixes()) typed_appl_preterm i
    
    and nocommapreterm i = 
        let infs = filter (fun (s, _) -> s <> ",") (infixes())
        mk_precedence infs typed_appl_preterm i
    
    and typed_appl_preterm i = (appl_preterm .>>. possibly(a(Resword ":") .>>. pretype |>> snd) |>> lmk_typed) i
    
    and appl_preterm i = 
        (pre_fix .>>. appl_preterm |>> (fun (x, y) -> Combp(Varp(x, dpty), y)) <|> binder_preterm .>>. many binder_preterm 
         |>> (fun (h, t) -> itlist (fun x y -> Combp(y, x)) (rev t) h)) i
    
    and binder_preterm i = 
        (a(Resword "let") .>>. leftbin (preterm |>> singleton1) (a(Resword "and")) (K (@)) "binding" .>>. a(Resword "in") 
         .>>. preterm |>> lmk_let 
         <|> (binder .>>. typed_apreterm .>>. many typed_apreterm .>>. a(Resword ".") .>>. preterm |>> lmk_binder) 
         <|> atomic_preterm) i
    
    and typed_apreterm i = (atomic_preterm .>>. possibly(a(Resword ":") .>>. pretype |>> snd) |>> lmk_typed) i
  
    and atomic_preterm i =
      (try_user_parser
        <|> ((a (Resword "(") .>>. a (Resword ":")) .>>. pretype .>>. a (Resword ")") |>> lmk_univ)
        <|> (string |>> pmk_string)
        <|> ((a (Resword "(")) .>>. (any_identifier |>> (fun s -> Varp(s,dpty))) .>>. a (Resword ")") |>> (snd << fst))
        <|> ((a (Resword "(")) .>>. preterm .>>. a (Resword ")") |>> (snd << fst))
        <|> ((a (Resword "if")) .>>. preterm .>>. a (Resword "then") .>>. preterm .>>. a (Resword "else") .>>. preterm |>> lmk_ite)
        <|> ((a (Resword "[")) .>>. elistof preterm (a (Resword ";")) "term" .>>. a (Resword "]") |>> (pmk_list << snd << fst))
        <|> ((a (Resword "{")) .>>.
              (elistof nocommapreterm (a (Ident ",")) "term" .>>.  a (Resword "}") |>> lmk_setenum
                <|> preterm .>>. a (Resword "|") .>>. preterm .>>. a (Resword "}") |>> lmk_setabs
                <|> preterm .>>. a (Resword "|") .>>. preterm .>>. a (Resword "|") .>>. preterm .>>. a (Resword "}") |>> lmk_setcompr) |>> snd)
        <|> ((a (Resword "match")) .>>. preterm .>>. a (Resword "with") .>>. clauses |>> (fun (((_,e),_),c) -> Combp(Combp(Varp("_MATCH",dpty),e),c)))
        <|> ((a (Resword "function")) .>>. clauses |>> (fun (_,c) -> Combp(Varp("_FUNCTION",dpty),c)))
        <|> ((a (Ident "#")) .>>. identifier .>>. possibly (a (Resword ".") .>>. identifier |>> snd) |>> lmk_decimal)
        <|> (identifier |>> (fun s -> Varp(s,dpty)))) i
  
    and pattern i = (preterm .>>. possibly(a(Resword "when") .>>. preterm |>> snd)) i
    
    and clause i = ((pattern .>>. (a(Resword "->") .>>. preterm |>> snd)) |>> pmk_pattern) i
    
    and clauses i = 
        ((possibly(a(Resword "|")) .>>. listof clause (a(Resword "|")) "pattern-match clause" |>> snd) 
         |>> end_itlist(fun s t -> Combp(Combp(Varp("_SEQPATTERN", dpty), s), t))) i
  
    (function
      | [Ident s] -> Varp(s,dpty),[]
      | inp -> preterm inp)
  