-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexer.mll
40 lines (38 loc) · 856 Bytes
/
lexer.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
(* File lexer.mll *)
{
open Parser
}
rule token = parse
| [' ' '\t' '\n'] {token lexbuf} (*skip blanks*)
(*| "0" as n {NUM(n)}*)
(*| '-'? ['1'-'9'] ['0'-'9']* as n {NUM(n)} *)
| '+' {PLUS}
| '-' {MINUS}
| '*' {MULTIPLY}
| '/' {DIVIDE}
| '%' {MOD}
| '^' {POWER}
| '(' {LEFTBRACKET}
| ')' {RIGHTBRACKET}
| 'T' {BOOL(true)}
| 'F' {BOOL(false)}
| '=' {EQUAL}
| "=/=" {NOTEQUAL}
| '<' {LT}
| '>' {GT}
| "<=" {LE}
| ">=" {GE}
| "fail" {FAIL}
| ['A'-'Z'] ['a'-'z' 'A'-'Z' '0'-'9' '_' ''']* as ided {VARIABLE (ided)}
| ['0'] ['a'-'z' 'A'-'Z' '_' ''']* as ided {ID (ided)}
| ['a'-'z' '1'-'9' '[' ']' '|'] ['a'-'z' 'A'-'Z' '0'-'9' '_' ''' '[' ']' '|']* as ided {ID (ided)}
| ":-" {IFF}
| ';' {SEMICOLON}
| ',' {COMMA}
| '.' {PERIOD}
| '[' {LEFTSQUARE}
| ']' {RIGHTSQUARE}
| '|' {PIPE}
| '!' {CUT}
| _ { token lexbuf }
| eof {EOF}