-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlexer.mll
More file actions
53 lines (39 loc) · 973 Bytes
/
lexer.mll
File metadata and controls
53 lines (39 loc) · 973 Bytes
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
{
open Parser
exception Quit
}
let digit = ['0'-'9']
let identchar = ['a'-'z' 'A'-'Z' '\'' '_' '0'-'9']
let ident = ['a'-'z'] identchar*
let ws = [' ' '\t' '\n' '\r']
rule comment = parse
| "\n" { token lexbuf }
| _ { comment lexbuf}
and token = parse
| ws { token lexbuf }
| "//" { comment lexbuf }
| digit+ as n { NUM (int_of_string n) }
| "+" { PLUS }
| "-" { MINUS }
| "*" { TIMES }
| "/" { DIV }
| "&&" { AND }
| "||" { OR }
| "<=" { LE }
| "<" { LT }
| ">=" { GE }
| ">" { GT }
| "!=" { NE }
| "==" { EQ }
| "=" { EQUAL }
| "if" { IF }
| "else" { ELSE }
| "while" { WHILE }
| "return" { RETURN }
| "(" { LPAREN }
| ")" { RPAREN }
| "{" { LBRACE }
| "}" { RBRACE }
| ";" { SEMI }
| ident as s { IDENT s }
| eof { EOF }