-
Notifications
You must be signed in to change notification settings - Fork 1
/
flexer.mll
70 lines (68 loc) · 1.33 KB
/
flexer.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
{
open Fparser
let reserved_words = [
("True", TRUE);
("False", FALSE);
("sum", SUM);
("active", ACTIVE);
("int", INT);
("integer", INT);
("thread", THREADS);
("forall", FORALL);
("exists", EXISTS);
("lambda", LAMBDA);
]
let special_constants = [
("threadIdx", Ftree.TID);
("blockIdx", Ftree.BID);
("blockDim", Ftree.BDIM);
("gridDim", Ftree.GDIM);
]
}
rule main = parse
[' ' '\009' '\012' '\n']+
| "//"[^'\n']*'\n' {main lexbuf}
| ['0'-'9']+ {INTV (int_of_string (Lexing.lexeme lexbuf))}
| ";" {SEMICOLON}
| "(" {LPAREN}
| ")" {RPAREN}
| "[" {LBRACKET}
| "]" {RBRACKET}
| "{" {LBRACE}
| "}" {RBRACE}
| "," {COMMA}
| "->" {IMPL}
| "||" {OR}
| "&&" {AND}
| "!" {EXCLAM}
| "==" {EQ}
| "=" {ASSIGN}
| "!=" {NEQ}
| "<=" {LE}
| ">=" {GE}
| "<" {LT}
| ">" {GT}
| "+" {PLUS}
| "-" {MINUS}
| "*" {MULT}
| "^" {POW}
| "/" {DIV}
| "%" {MOD}
| "." {DOT}
| "%%" {SECTIONSEP}
| "@" {AT}
| ":" {COLON}
(* | "__syncthreads()" {SYNC} *)
| ['a'-'z' 'A'-'Z' '_']['a'-'z' 'A'-'Z' '_' '0'-'9']* {
let id = Lexing.lexeme lexbuf in
try List.assoc id reserved_words
with Not_found ->
try let t = List.assoc id special_constants in
CONST (t, accessor lexbuf)
with Not_found -> ID id
}
| eof {EOF}
and accessor = parse
".x" {Ftree.X}
| ".y" {Ftree.Y}
| ".z" {Ftree.Z}