-
Notifications
You must be signed in to change notification settings - Fork 0
/
scanner.mll
76 lines (72 loc) · 2.11 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
(* Ocamllex scanner for Strux *)
{ open Parser }
let whitespace = [' ' '\t' '\r' '\n']
let digits = ['0'-'9']
let integer = digits+
let decimal = ['.']
let esc = '\\' ['\\' ''' '"' 'n' 'r' 't']
let ascii = ([' '-'!' '#'-'[' ']'-'~'])
let string = '"' ( (ascii | esc)* as s) '"'
let float = digits* decimal digits+ | digits+ decimal digits*
let alphabet = ['a'-'z' 'A'-'Z']
let alphanumund = alphabet | digits | '_'
let id = alphabet alphanumund*
rule token = parse
whitespace { token lexbuf } (* Whitespace *)
| ":(" { comment lexbuf } (* Comments *)
| '(' { LPAREN }
| ')' { RPAREN }
| '{' { LBRACE }
| '}' { RBRACE }
| '[' { LBRACK }
| ']' { RBRACK }
| ';' { SEMI }
| ',' { COMMA }
| '+' { PLUS }
| '-' { MINUS }
| '*' { TIMES }
| '/' { DIVIDE }
| '%' { MOD }
| '.' { DOT }
| "++" { INCR }
| "--" { DECR }
| '=' { ASSIGN }
| "::" { DOUBLECOL }
| "==" { EQ }
| "!=" { NEQ }
| '<' { LT }
| "<=" { LEQ }
| ">" { GT }
| ">=" { GEQ }
| "and" { AND }
| "or" { OR }
| "not" { NOT }
| "if" { IF }
| "elif" { ELIF }
| "else" { ELSE }
| "for" { FOR }
| "while" { WHILE }
| "return" { RETURN }
| "num" { NUM }
| "int" { INT }
| "bool" { BOOL }
| "string" { STRING }
| "void" { VOID }
| "true" { TRUE }
| "false" { FALSE }
| "new" { NEW }
| "null" { NULL }
| "Queue" { QUEUE }
| "LinkedList" { LINKEDLIST }
| "BSTree" { BSTREE }
| "Stack" { STACK }
| integer as lxm { INT_LITERAL(int_of_string lxm) }
| id as lxm { ID(lxm) }
| float as fltlit { NUM_LITERAL(float_of_string fltlit) }
| digits+ as intlit { INT_LITERAL(int_of_string intlit) }
| string { STRING_LITERAL(s) }
| eof { EOF }
| _ as char { raise (Failure("illegal character " ^ Char.escaped char)) }
and comment = parse
"):" { token lexbuf }
| _ { comment lexbuf }