{ open Funparse exception EndInput let rec unescape s = let strpop s = s.[0], String.sub s 1 (String.length s - 1) and chr2str c = Printf.sprintf "%c" c in match String.length s with | 0 -> "" | 1 -> s | len -> let c1,s = strpop s in if c1 = '\\' then let c2,s = strpop s in if c2 = 'n' then "\n" ^ (unescape s) else if c2 = 't' then "\t" ^ (unescape s) else (chr2str c2) ^ (unescape s) else (chr2str c1) ^ (unescape s) } (* You can assign names to commonly-used regular expressions in this part of the code, to save the trouble of re-typing them each time they are used *) let numeric = ['0' - '9'] let letter =['a' - 'z' 'A' - 'Z' '_'] rule mytoken = parse | [' ' '\t' '\n'] { mytoken lexbuf } (* skip over whitespace *) (*YOUR CODE GOES HERE...*) | eof { raise EndInput } (*YOU CAN DEFINE NEW rules HERE*) (* do not modify this function: *) { let lextest s = let rec lbuf = Lexing.from_string s and lextest_aux () = try let res = mytoken lbuf in res :: lextest_aux () with EndInput -> [] in lextest_aux () }