-
Notifications
You must be signed in to change notification settings - Fork 0
/
scanner.mll
63 lines (58 loc) · 1.59 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
(* Ocamllex scanner for TPL *)
{ open Parser }
(* Add flaot and good string support *)
rule token = parse
[' ' '\t' '\r' '\n'] { token lexbuf } (* Whitespace *)
| "/*" { multilinecomment lexbuf } (* Comments *)
| "//" { singlelinecomment lexbuf } (* Comments *)
| '"' ([^ '"']* as strliteral) '"' { STRLITERAL(strliteral) }
| (['0'-'9']* '.' ['0'-'9']*) as l { FLOATLITERAL(l)}
| '(' { LPAREN }
| ')' { RPAREN }
| '{' { LBRACE }
| '}' { RBRACE }
| '[' { LBRACKET }
| ']' { RBRACKET }
| ';' { SEMI }
| '.' { DOT }
| ',' { COMMA }
| '+' { PLUS }
| '-' { MINUS }
| '*' { TIMES }
| '/' { DIVIDE }
| '=' { ASSIGN }
| "==" { EQ }
| "!=" { NEQ }
| '<' { LT }
| "<=" { LEQ }
| ">" { GT }
| ">=" { GEQ }
| "&&" { AND }
| "||" { OR }
| "!" { NOT }
| "if" { IF }
| "else" { ELSE }
| "for" { FOR }
| "while" { WHILE }
| "return" { RETURN }
| "array int" { INTARRAY }
| "array float" { FLOATARRAY }
| "array string" { STRARRAY }
| "int" { INT }
| "string" { STRING }
| "float" { FLOAT }
| "table" { TABLE }
| "bool" { BOOL }
| "void" { VOID }
| "true" { TRUE }
| "false" { FALSE }
| ['0'-'9']+ as lxm { LITERAL(int_of_string lxm) }
| ['a'-'z' 'A'-'Z']['a'-'z' 'A'-'Z' '0'-'9' '_']* as lxm { ID(lxm) }
| eof { EOF }
| _ as char { raise (Failure("illegal character " ^ Char.escaped char)) }
and multilinecomment = parse
"*/" { token lexbuf }
| _ { multilinecomment lexbuf }
and singlelinecomment = parse
['\r' '\n'] { token lexbuf }
| _ { singlelinecomment lexbuf }