-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexer.mll
executable file
·46 lines (44 loc) · 2.14 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
35
36
37
38
39
40
41
42
43
44
45
46
{
exception Lexer_exception of string
}
let digit = ['0'-'9']
let integer = ['0'-'9']['0'-'9']*
let id = ['a'-'z''A'-'Z'] ['a'-'z' 'A'-'Z' '0'-'9']*
rule scan = parse
| [' ' '\t']+ { scan lexbuf }
| ";\n" { Parser.EOL }
| "end" { Parser.END }
| '(' { Parser.LPAREN }
| ')' { Parser.RPAREN }
| '[' { Parser.LSQUARE }
| ']' { Parser.RSQUARE }
| ':' { Parser.COLON }
| '-' { Parser.SUBTRACT }
| '+' { Parser.ADD }
| '=' { Parser.EQ }
| '.' { Parser.DOT }
| "->" { Parser.RTARROW }
| integer as s { Parser.INTEGER((int_of_string s)) }
| "if" { Parser.IF }
| "then" { Parser.THEN }
| "else" { Parser.ELSE }
| "true" { Parser.BOOLEAN(true) }
| "false" { Parser.BOOLEAN(false) }
| "and" { Parser.AND }
| "or" { Parser.OR }
| "not" { Parser.NOT }
| "let" { Parser.LET }
| "in" { Parser.IN }
| "fun" { Parser.FUN }
| "stack" { Parser.STACK }
| "push" { Parser.PUSH }
| "top" { Parser.TOP }
| "pop" { Parser.POP }
| "map" { Parser.MAP }
| "add" { Parser.ADD }
| "tree" { Parser.TREE }
| "insert" { Parser.INSTREE }
| "delete" { Parser.DELTREE }
| id as s { Parser.ID(s) }
| ',' { Parser.COMMA }
| eof { Parser.EOF }