mirror of
https://github.com/LucasVbr/croissant.git
synced 2026-05-13 17:12:10 +00:00
28 lines
503 B
OCaml
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) } |