-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlexer.mll
49 lines (43 loc) · 979 Bytes
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
{
open Lexing
open Parser
open Printf
}
let dec_digit = ['0'-'9']
let signed_int = dec_digit+ | ('-' dec_digit+)
let ident = ['a'-'z' 'A'-'Z' '_']['a'-'z' 'A'-'Z' '0'-'9' '_']*
let blank = [' ' '\t']+
rule token = parse
| blank { token lexbuf }
| '\n' { new_line lexbuf; token lexbuf }
| signed_int as x { NUM (int_of_string x) }
| "def" { DEF }
| "add1" { ADD1 }
| "sub1" { SUB1 }
| "print" { PRINT }
| "if" { IF }
| "true" { TRUE }
| "false" { FALSE }
| "isbool" { ISBOOL }
| "isnum" { ISNUM }
| "istuple" { ISTUPLE }
| ":" { COLON }
| "else:" { ELSECOLON }
| "end" { END }
| "let" { LET }
| "in" { IN }
| "==" { EQEQ }
| "=" { EQUAL }
| "," { COMMA }
| "(" { LPAREN }
| ")" { RPAREN }
| "[" { LBRACK }
| "]" { RBRACK }
| "+" { PLUS }
| "-" { MINUS }
| "*" { TIMES }
| "<" { LESS }
| ">" { GREATER }
| ident as x { ID x }
| eof { EOF }
| _ as c { failwith (sprintf "Unrecognized character: %c" c) }