lexer.mll 838 B

12345678910111213141516171819202122232425262728293031323334353637
  1. {
  2. open Lexing
  3. open Parser
  4. exception Syntax_error of string
  5. let next_line lexbuf =
  6. let pos = lexbuf.lex_curr_p in
  7. lexbuf.lex_curr_p <- {
  8. pos with pos_bol = lexbuf.lex_curr_pos;
  9. pos_lnum = pos.pos_lnum + 1
  10. }
  11. }
  12. rule token = parse
  13. | ';' { SEMICOL }
  14. | '!' { EXCLAM }
  15. | '+' { PLUS }
  16. | '-' { MINUS }
  17. | '#' { HASH }
  18. | '*' { OMEGA }
  19. | '(' { LPAREN }
  20. | ')' { RPAREN }
  21. (*
  22. | '{' { LBRACE }
  23. | '}' { RBRACE }
  24. *)
  25. | ['0'-'9']+ as i { NUMBER (int_of_string i) }
  26. | ['A'-'Z'] as c { UPPER c }
  27. | ['a'-'z'] as c { LOWER c }
  28. | '\r' | '\n' | "\r\n" { next_line lexbuf; token lexbuf }
  29. | [' ''\t']+ { token lexbuf }
  30. | eof | '\000' { EOF }
  31. | _ as chr { raise (Syntax_error ("unexpected '" ^ Char.escaped chr ^ "'")) }