-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexp.mll
More file actions
27 lines (22 loc) · 747 Bytes
/
Copy pathexp.mll
File metadata and controls
27 lines (22 loc) · 747 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
(* File exp.mll *)
{
type token = ID of string | INT of int
| PLUS | MINUS | STAR | SLASH
| LBRA | RBRA | EOF
exception LEX of string
}
let int = '-'? ['0'-'9'] ['0'-'9']*
let white = [' ' '\t' '\n']+
let id = ['a'-'z' 'A'-'Z' '_'] ['a'-'z' 'A'-'Z' '0'-'9' '_']*
rule token = parse
| white { token lexbuf }
| int { INT (int_of_string (Lexing.lexeme lexbuf)) }
| id { ID (Lexing.lexeme lexbuf) }
| '+' { PLUS }
| '-' { MINUS }
| '*' { STAR }
| '/' { SLASH }
| '(' { LBRA }
| ')' { RBRA }
| eof { EOF }
| _ { raise (LEX ("Unexpected char: " ^ Lexing.lexeme lexbuf)) }