-
Notifications
You must be signed in to change notification settings - Fork 0
/
scanner.mll
80 lines (75 loc) · 1.95 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
(*
scanner.mll
@authors Aidan Barg
Abby Larson
Claudia Aranda Barrios
Steven Oh
*)
{ open Parser }
let digit = ['0' - '9']
let digits = digit+
rule token = parse
[' ' '\t' '\r' '\n'] { token lexbuf } (* Whitespace *)
| "#" { comment lexbuf } (* Comments *)
(* numbers *)
| '-'? digits as lxm { LITERAL(int_of_string lxm) }
| '-'? digits '.' digit* as lxm { FLIT(lxm) }
| '-'? '.' digits as lxm { FLIT(lxm) }
(* brackets *)
| '(' { LPAREN }
| ')' { RPAREN }
| '[' { LBRAC }
| ']' { RBRAC }
| '{' { LBRACE }
| '}' { RBRACE }
(* delimiters *)
| ';' { SEMI }
| '.' { DOT }
| ',' { COMMA }
(* binary operators *)
| '+' { PLUS }
| '-' { MINUS }
| '*' { TIMES }
| '/' { DIVIDE }
| '=' { ASSIGN }
(* edge *)
| "->" { ARROW }
(* comparison operators *)
| "==" { EQ }
| "!=" { NEQ }
| '<' { LT }
| "<=" { LEQ }
| ">" { GT }
| ">=" { GEQ }
(* logical operators *)
| "and" { AND }
| "or" { OR }
| "not" { NOT }
(* statements *)
| "if" { IF }
| "else" { ELSE }
| "for" { FOR }
| "while" { WHILE }
| "return" { RETURN }
(* types *)
| "int" { INT }
| "bool" { BOOL }
| "float" { FLOAT }
| "list" { LIST }
| "void" { VOID }
| "node" { NODE }
| "edge" { EDGE }
| "graph" { GRAPH }
| "string" { STRING_T }
(* boolean literals *)
| "true" { BLIT(true) }
| "false" { BLIT(false) }
(* other *)
| ['a'-'z' 'A'-'Z']['a'-'z' 'A'-'Z' '0'-'9' '_']* as lxm { ID(lxm) }
| '"'['a'-'z' 'A'-'Z' '0'-'9' '_' ' ' '\n' '!' '@' '$' '%' '^' '&' '*' '(' ')' '-' '+' '=' '\\' ':']*'"' as lxm { STRING((String.sub lxm 1 ((String.length lxm) - 2))) }
| eof { EOF }
| _ as char { raise (Failure("illegal character " ^ Char.escaped char)) }
and comment = parse
"\n" { token lexbuf }
| eof { EOF }
| _ { comment lexbuf }