-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlexer.mll
85 lines (78 loc) · 1.35 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
{
open Lexing
open Parser
let keywords = Hashtbl.create 30
let () =
List.iter
(fun (x,y) -> Hashtbl.add keywords x y)
[ "MODULE", MODULE;
"process", PROCESS;
"boolean", BOOLEAN;
"VAR", VAR;
"init", INIT;
"next", NEXT;
"SPEC", SPEC;
"ASSIGN", ASSIGN;
"case", CASE;
"esac", ESAC;
"AX", AX;
"EX", EX;
"AG", AG;
"EG", EG;
"AF", AF;
"EF", EF;
"A", A;
"E", E;
"U", U;
"R", R;
"TRUE", TRUE;
"FALSE", FALSE
]
let newline lexbuf =
let pos = lexbuf.lex_curr_p in
lexbuf.lex_curr_p <-
{pos with pos_lnum = pos.pos_lnum + 1; pos_bol = pos.pos_cnum }
let string_buf = Buffer.create 1024
exception Lexical_errof of string
}
let space = [' ' '\t' '\r']
let alpha = ['a'-'z' 'A'-'Z']
let letter = alpha | '_'
let digit = ['0'-'9']
let ident = (letter) (letter | digit)*
rule token = parse
| '\n'
{newline lexbuf; token lexbuf}
| space+
{token lexbuf}
| ident as id (* identifiers *)
{ try
Hashtbl.find keywords id
with Not_found ->
IDENT id
}
| "--" {comment lexbuf; token lexbuf}
| '(' {LP}
| ')' {RP}
| '[' {LB}
| ']' {RB}
| '{' {LCB}
| '}' {RCB}
| ":=" {EQDEF}
| '=' {EQ}
| '!' {NOT}
| '|' {OR}
| '&' {AND}
| "=>" {IMP}
| "<=>" {EQUV}
| ',' {COMMA}
| ':' {COLON}
| ';' {SEMI}
| eof {EOF}
and comment = parse
| '\n'
{ () }
| eof
{()}
| _
{ comment lexbuf }