Files
croissant/lib/lexer.mll
T
2024-07-02 15:33:58 +02:00

28 lines
503 B
OCaml

(* lib/lexer.mll *)
{
open Parser
exception Error of char
}
let line_comment = "//" [^ '\n']*
let digit = ['0'-'9']
let integer = digit+
rule token = parse
| [' ' '\t'] | line_comment { token lexbuf }
| ['\n'] { Lexing.new_line lexbuf; token lexbuf }
| '+' { PLUS }
| '-' { MINUS }
| '*' { TIMES }
| '/' { DIVIDE }
| ';' { SEMICOLON }
| integer as lxm { INT(int_of_string lxm) }
| '(' { LPAREN }
| ')' { RPAREN }
| eof { EOF }
| _ as c { raise (Error c) }