Advertisement
tobast

Untitled

Jun 28th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. (*
  2. * Strategies interpreter
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. *)
  17.  
  18. {
  19. open Lexing
  20. open LlamParser
  21. exception LexicalError of string
  22.  
  23. let newline lexbuf =
  24. let pos = lexbuf.lex_curr_p in
  25. lexbuf.lex_curr_p <-
  26. { pos with pos_lnum = pos.pos_lnum + 1; pos_bol = pos.pos_cnum }
  27. }
  28. let var = [ 'a'-'z' 'A'-'Z' '0'-'9' '_' ]
  29.  
  30. rule token = parse
  31. | '\n' { newline lexbuf ; token lexbuf }
  32. | [' ' '\t']+ { token lexbuf }
  33. | '(' { Tlpar }
  34. | ')' { Trpar }
  35. | ',' { Tcomma }
  36. | ['.'] { Tdot }
  37. | ['\\' '^'] { Tlambda }
  38. | "λ" { Tlambda }
  39. | var as v { Tvar(v) }
  40. | _ as c { raise @@ LexicalError ("Illegal character: \
  41. '"^(String.make 1 c)^"'.") }
  42. | eof { Teof }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement