-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscanner.mll
98 lines (90 loc) · 2.19 KB
/
scanner.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
86
87
88
89
90
91
92
93
94
95
96
97
98
(* Authors:
Daniel Benett deb2174
Seth Benjamin sjb2190
Jennifer Bi jb3495
Jessie Liu jll2219
*)
(* Ocammllex scanner for giraph *)
{ open Parser }
(* Definitions *)
let digit = ['0'-'9']
let decimal = ((digit+ '.' digit*) | ('.' digit+))
let letter = ['a'-'z' 'A'-'Z']
(* Rules *)
rule token = parse
[ ' ' '\t' '\r' '\n'] { token lexbuf } (* to ignore whitespace *)
| "!~" { comment lexbuf }
| ',' { COMMA }
| '.' { DOT }
| ';' { SEMI }
| ':' { COLON }
| '\'' { SINGLEQUOTE }
| '\"' { DOUBLEQUOTE }
(* scoping *)
| '(' { LPAREN }
| ')' { RPAREN }
| '{' { LBRACE }
| '}' { RBRACE }
| '[' { LBRACK }
| ']' { RBRACK }
(* keywords *)
| "for" { FOR }
| "while" { WHILE }
| "for_node" {FOR_NODE}
| "for_edge" {FOR_EDGE}
| "bfs" {BFS}
| "dfs" {DFS}
| "if" { IF }
| "then" { THEN }
| "else" { ELSE }
| "bool" { BOOL }
| "float" { FLOAT }
| "int" { INT }
| "string" { STRING }
| "graph" { GRAPH }
| "node" { NODE }
| "wegraph" { WEGRAPH }
| "digraph" { DIGRAPH }
| "wedigraph" { WEDIGRAPH }
| "map" { MAP }
(* | "break" { BREAK }
| "continue" { CONTINUE } *)
| "return" { RETURN }
| "void" { VOID }
(* operators *)
| '+' { PLUS }
| '-' { MINUS }
| '*' { TIMES }
| '/' { DIVIDE }
| '=' { ASSIGN }
(* | "+=" { PLUSEQ }
| "-=" { MINUSEQ }
| "*=" { TIMESEQ }
| "/=" { DIVEQ } *)
| '%' { MOD }
| "&&" { AND }
| "||" { OR }
(* | '&' { INTERSECTION }
| '|' { UNION } *)
| '!' { NOT }
| "==" { EQ }
| "!=" { NEQ }
| ">=" { GEQ }
| "<=" { LEQ }
| '>' { GT }
| '<' { LT }
| "->" { RARROW }
| "<-" { LARROW }
| "<->" { DIARROW }
| "--" { EDGE }
(* literals and IDs *)
| digit+ as lxm { INT_LIT(int_of_string lxm) }
| decimal as lxm { FLOAT_LIT(float_of_string lxm) }
| ("true" | "false") as lxm { BOOL_LIT(bool_of_string lxm) }
| letter (letter | digit | '_')* as lxm { ID(lxm) }
| '\"' ([^'\"']* as lxm) '\"' { STRING_LIT(lxm) }
| eof { EOF }
| _ as char { raise (Failure("illegal character " ^ Char.escaped char)) }
and comment = parse
"~!" { token lexbuf }
| _ { comment lexbuf }