-
Notifications
You must be signed in to change notification settings - Fork 1
/
lexer.mll
44 lines (42 loc) · 958 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
{
open Parser
exception LexingError
}
let digits = ['0' - '9']
let alpha = ['a' - 'z' 'A' - 'Z']
let space = ['\n' '\r' '\t' ' ']
let printable = [' ' - '~']
let str_char = printable # ['"']
rule lexer = parse
| "//" [^'\n']* '\n'? { lexer lexbuf }
| eof { Eof }
| space+ { lexer lexbuf }
| "FUNC" { Func }
| "PROTO" { Proto }
| "INT" { IntType }
| "VOID" { VoidType }
| "PRINT" { Print }
| "READ" { Read }
| "RETURN" { Return }
| ":=" { Assign }
| "IF" { If }
| "THEN" { Then }
| "ELSE" { Else }
| "FI" { Fi }
| "WHILE" { While }
| "DO" { Do }
| "DONE" { Done }
| "," { Comma }
| "(" { LeftPar }
| ")" { RightPar }
| "{" { LeftCurly }
| "}" { RightCurly }
| "[" { LeftSquare }
| "]" { RightSquare }
| "+" { Plus }
| "-" { Minus }
| "*" { Times }
| "/" { Divide }
| digits+ as n { Int (int_of_string n) }
| alpha (alpha | digits)* as i { Id i }
| "\"" (str_char* as str) "\"" { Str str }