-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlexer.mll
34 lines (32 loc) · 1.01 KB
/
lexer.mll
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
{
open Parser (* The type token is defined in parser.mli *)
open Lexing
exception Eof
}
rule token = parse
[' ' '\t' '\n'] { token lexbuf } (* skip blanks *)
| '+' { PLUS }
| '-' { MINUS }
| '<' { LTHAN }
| '>' { GTHAN }
| "==" { EQUALITY }
| '(' { LPAREN }
| ')' { RPAREN }
| '{' { LBRACE }
| '}' { RBRACE }
| ';' { SEMICOLON }
| '=' { EQUALS }
| "let" { LET }
| ':' { COLON }
| "i32" { I32_TYPE }
| "u32" { U32_TYPE }
| "bool" { BOOL_TYPE }
| "while" { WHILE }
| "if" { IF }
| "else" { ELSE }
| "true" { TRUE }
| "false" { FALSE }
| ['0'-'9']+ as lxm { INT(int_of_string lxm) }
| ['a'-'z' 'A'-'Z']+ as lxm { IDENT(lxm) }
| eof { raise Eof }
| _ { Errors.complain ("ERROR L000: Illegal character " ^ (Char.escaped(Lexing.lexeme_char lexbuf 0))) }