blob: 0f8e9ab14ff5c97f77e79ab5135b01e1cf68e572 [file] [log] [blame]
Jason Sams326e0dd2009-05-22 14:03:28 -07001%option stack
2
3%x comment
4%x api_entry
5%x api_entry2
6%x api_entry_param
7%x var_type
8
9DIGIT [0-9]
10ID [a-zA-Z_][a-zA-Z0-9_]*
11
12
13 int num_lines = 0;
14
15 typedef struct {
16 int isConst;
17 int type;
18 int bits;
19 int ptrLevel;
20 char name[256];
21 char typename[256];
22 } VarType;
23
24 VarType *currType = 0;
25
26 typedef struct {
27 char name[256];
28 int sync;
29 int paramCount;
30 VarType ret;
31 VarType params[16];
32 } ApiEntry;
33
34 ApiEntry apis[128];
35 int apiCount = 0;
36
37 int typeNextState;
38
39%%
40
41"/*" BEGIN(comment);
42<comment>[^*\n]* /* eat anything that's not a '*' */
43<comment>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */
44<comment>\n ++num_lines;
45<comment>"*"+"/" BEGIN(INITIAL);
46
47<*>" " //printf("found ' '\n");
48<*>"\n" ++num_lines; //printf("found lf \n");
49
50{ID} {
51 memset(&apis[apiCount], 0, sizeof(ApiEntry));
52 memcpy(apis[apiCount].name, yytext, yyleng);
53 BEGIN(api_entry);
54 }
55
56<api_entry>"{" {
57 BEGIN(api_entry2);
58 }
59
60<api_entry2>"sync" {
61 apis[apiCount].sync = 1;
62 }
63
64<api_entry2>"ret" {
65 currType = &apis[apiCount].ret;
66 typeNextState = api_entry2;
67 BEGIN(var_type);
68 }
69
70<api_entry2>"param" {
71 currType = &apis[apiCount].params[apis[apiCount].paramCount];
72 apis[apiCount].paramCount++;
73 typeNextState = api_entry_param;
74 BEGIN(var_type);
75 }
76
77<var_type>"const" {
78 currType->isConst = 1;
79 }
80
81<var_type>"i8" {
82 currType->type = 1;
83 currType->bits = 8;
84 BEGIN(typeNextState);
85 }
86
87<var_type>"i16" {
88 currType->type = 1;
89 currType->bits = 16;
90 BEGIN(typeNextState);
91 }
92
93<var_type>"i32" {
94 currType->type = 1;
95 currType->bits = 32;
96 BEGIN(typeNextState);
97 }
98
99<var_type>"i64" {
100 currType->type = 1;
101 currType->bits = 64;
102 BEGIN(typeNextState);
103 }
104
105<var_type>"u8" {
106 currType->type = 2;
107 currType->bits = 8;
108 BEGIN(typeNextState);
109 }
110
111<var_type>"u16" {
112 currType->type = 2;
113 currType->bits = 16;
114 BEGIN(typeNextState);
115 }
116
117<var_type>"u32" {
118 currType->type = 2;
119 currType->bits = 32;
120 BEGIN(typeNextState);
121 }
122
123<var_type>"u64" {
124 currType->type = 2;
125 currType->bits = 64;
126 BEGIN(typeNextState);
127 }
128
129<var_type>"f" {
130 currType->type = 3;
131 currType->bits = 32;
132 BEGIN(typeNextState);
133 }
134
135<var_type>"d" {
136 currType->type = 3;
137 currType->bits = 64;
138 BEGIN(typeNextState);
139 }
140
141<var_type>{ID} {
142 currType->type = 4;
143 currType->bits = 32;
144 memcpy(currType->typename, yytext, yyleng);
145 BEGIN(typeNextState);
146 }
147
148<api_entry_param>"*" {
149 currType->ptrLevel ++;
150 }
151
152<api_entry_param>{ID} {
153 memcpy(currType->name, yytext, yyleng);
154 BEGIN(api_entry2);
155 }
156
157
158<api_entry2>"}" {
159 apiCount++;
160 BEGIN(INITIAL);
161 }
162
163
164%%
165
166
167int yywrap()
168{
169 return 1;
170}
171