-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscanner.mll
38 lines (36 loc) · 1.52 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
{ open Parser } (* Get the token types *)
rule token = parse
[' ' '\t' '\r' '\n'] { token lexbuf } (* Whitespace *)
| "/*" { comment lexbuf } (* Comments *)
| '(' { LPAREN } | ')' { RPAREN } (* Punctuation *)
| '{' { LBRACE } | '}' { RBRACE }
| '[' { LBRACK } | ']' { RBRACK }
| ';' { SEMI } | ',' { COMMA }
| '+' { PLUS } | '-' { MINUS }
| '*' { TIMES } | '/' { DIVIDE }
| '%' { MOD } | ':' { COLON }
| '=' { ASSIGN }
| '<' { LT } | '>' { GT }
| "==" { EQ } | "!=" { NEQ }
| "<=" { LEQ } | ">=" { GEQ }
| '!' { NOT }
| '|' { OR } | '&' { AND } (* Short circuits *)
| "accept" { ACCEPT } | "reject" { REJECT } (*test functions*)
| "@" { ASSERT } | "unit" { UNIT } | '.' { ACCESS }
| "else" { ELSE } | "if" { IF } (* Keywords *)
| "while" { WHILE } | "for" { FOR }
| "return" { RETURN } | "accept" { ACCEPT }
| "struct" { STRUCT } | "reject" { REJECT }
| "void" { VOID }
| "bool" { BOOL } | "int" { INT } | "str" { STRING }
| "equals" { EQUALS }
| '"'('\\'_ |[^'"'])*'"' as str { STRING_LITERAL(str) } (* Strings *)
| ['0'-'9']+ as lxm { INT_LITERAL(int_of_string lxm) } (* Integers *)
| "true" | "false" as boolean { BOOL_LITERAL(bool_of_string boolean) }
| eof { EOF } (* End-of-file *)
| ['a'-'z' 'A'-'Z']['a'-'z' 'A'-'Z' '0'-'9' '_']* as lxm { ID(lxm) }
| _ as char { raise (Failure("illegal character " ^
Char.escaped char)) }
and comment = parse
"*/" { token lexbuf } (* End-of-comment *)
| _ { comment lexbuf } (* Eat everything else *)