-
Notifications
You must be signed in to change notification settings - Fork 0
/
lex.mll
47 lines (45 loc) · 1.02 KB
/
lex.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 Parse
}
let white = [' ' '\t' '\r']+
let digit = ['0'-'9']
let letter = ['a'-'z' 'A'-'Z' '_']
let var = letter+
rule token = parse
| white { token lexbuf }
| '\n' { Lexing.new_line lexbuf; token lexbuf }
| "--" [^'\n']* { token lexbuf }
| "(" { LPAREN }
| ")" { RPAREN }
| "->" { ARROW }
| "," { COMMA }
| "." { DOT }
| "::" { COL }
| "=" { EQ }
| "<>" { NE }
| "&&" { AND }
| "||" { OR }
| "+" { PLUS }
| "-" { MINUS }
| "*" { STAR }
| "/" { SLASH }
| "forall" { FORALL }
| "fun" { FUN }
| "if" { IF }
| "let" { LET }
| "in" { IN }
| "then" { THEN }
| "else" { ELSE }
| "true" { BOOL true }
| "false" { BOOL false }
| digit+ { INT (int_of_string (Lexing.lexeme lexbuf)) }
| "`" var "`"
{
let v = Lexing.lexeme lexbuf in
let len = Lexing.lexeme_end lexbuf - Lexing.lexeme_start lexbuf in
BVAR (String.sub v 1 (len - 2))
}
| "'" var { TVAR (Lexing.lexeme lexbuf) }
| var { VAR (Lexing.lexeme lexbuf) }
| eof { EOF }
| _ { failwith "Lexing error" }