uann/ocaml_yacc/lexer.mll

22 lines
629 B
OCaml

(* File lexer.mll *)
{
open Parser(* The type token is defined in parser.mli *)
exception Eof
}
rule token = parse
[' ' '\t'] { token lexbuf } (* skip blanks *)
| ['\n' ]{ EOL }
| ['i']['n'] { IN }
| ('_'|['a'-'z']|['A'-'Z']) as lxm { ID((String.make 1 lxm)) }
| ('_'|['a'-'z']|['A'-'Z'])(['0'-'9']|'_'|['a'-'z']|['A'-'Z'])+ as lxm { ID(lxm) }
| ['0'-'9']+ as lxm { INT(lxm) }
| '+' { PLUS }
| '-' { MINUS }
| '*' { TIMES }
| '/' { DIV }
| '(' { LPAREN }
| ')' { RPAREN }
| ['-']['>'] { IMPLY }
| ['=']['>'] { FUNC }
| '=' { ASSIGN }
| eof { raise Eof }