blob: c8af89167e1b12b9cddaf1c2f22b9ec6c958e973 [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
Joe Onorato84614dd2009-08-10 15:01:51 -070012 #include "spec.h"
Jason Sams326e0dd2009-05-22 14:03:28 -070013
14 int num_lines = 0;
15
Jason Sams326e0dd2009-05-22 14:03:28 -070016 VarType *currType = 0;
17
Jason Sams326e0dd2009-05-22 14:03:28 -070018 ApiEntry apis[128];
19 int apiCount = 0;
20
21 int typeNextState;
22
Alex Sakhartchouk70b83c12011-04-06 10:57:51 -070023 void checkPointerType() {
24 VarType *lastType = currType;
25 if (lastType->ptrLevel) {
26 currType = &apis[apiCount].params[apis[apiCount].paramCount];
27 currType->type = 4;
28 sprintf(currType->typeName, "%s", "size_t");
29 if (lastType->name[0]) {
30 sprintf(currType->name, "%s_length", lastType->name);
31 }
32 apis[apiCount].paramCount++;
33 }
34 }
35
Joe Onorato84614dd2009-08-10 15:01:51 -070036 extern "C" int yylex();
37
Jason Sams326e0dd2009-05-22 14:03:28 -070038%%
39
40"/*" BEGIN(comment);
41<comment>[^*\n]* /* eat anything that's not a '*' */
42<comment>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */
43<comment>\n ++num_lines;
44<comment>"*"+"/" BEGIN(INITIAL);
45
46<*>" " //printf("found ' '\n");
47<*>"\n" ++num_lines; //printf("found lf \n");
48
49{ID} {
50 memset(&apis[apiCount], 0, sizeof(ApiEntry));
51 memcpy(apis[apiCount].name, yytext, yyleng);
52 BEGIN(api_entry);
53 }
54
55<api_entry>"{" {
56 BEGIN(api_entry2);
57 }
58
59<api_entry2>"sync" {
60 apis[apiCount].sync = 1;
61 }
62
Jason Sams9397e302009-08-27 20:23:34 -070063<api_entry2>"handcodeApi" {
64 apis[apiCount].handcodeApi = 1;
65 }
66
67<api_entry2>"handcodePlay" {
68 apis[apiCount].handcodePlay = 1;
69 }
70
Jason Sams326e0dd2009-05-22 14:03:28 -070071<api_entry2>"ret" {
72 currType = &apis[apiCount].ret;
73 typeNextState = api_entry2;
74 BEGIN(var_type);
75 }
76
77<api_entry2>"param" {
78 currType = &apis[apiCount].params[apis[apiCount].paramCount];
79 apis[apiCount].paramCount++;
80 typeNextState = api_entry_param;
81 BEGIN(var_type);
82 }
83
84<var_type>"const" {
85 currType->isConst = 1;
86 }
87
88<var_type>"i8" {
89 currType->type = 1;
90 currType->bits = 8;
91 BEGIN(typeNextState);
92 }
93
94<var_type>"i16" {
95 currType->type = 1;
96 currType->bits = 16;
97 BEGIN(typeNextState);
98 }
99
100<var_type>"i32" {
101 currType->type = 1;
102 currType->bits = 32;
103 BEGIN(typeNextState);
104 }
105
106<var_type>"i64" {
107 currType->type = 1;
108 currType->bits = 64;
109 BEGIN(typeNextState);
110 }
111
112<var_type>"u8" {
113 currType->type = 2;
114 currType->bits = 8;
115 BEGIN(typeNextState);
116 }
117
118<var_type>"u16" {
119 currType->type = 2;
120 currType->bits = 16;
121 BEGIN(typeNextState);
122 }
123
124<var_type>"u32" {
125 currType->type = 2;
126 currType->bits = 32;
127 BEGIN(typeNextState);
128 }
129
130<var_type>"u64" {
131 currType->type = 2;
132 currType->bits = 64;
133 BEGIN(typeNextState);
134 }
135
136<var_type>"f" {
137 currType->type = 3;
138 currType->bits = 32;
139 BEGIN(typeNextState);
140 }
141
142<var_type>"d" {
143 currType->type = 3;
144 currType->bits = 64;
145 BEGIN(typeNextState);
146 }
147
148<var_type>{ID} {
149 currType->type = 4;
150 currType->bits = 32;
Joe Onorato84614dd2009-08-10 15:01:51 -0700151 memcpy(currType->typeName, yytext, yyleng);
Jason Sams326e0dd2009-05-22 14:03:28 -0700152 BEGIN(typeNextState);
153 }
154
155<api_entry_param>"*" {
156 currType->ptrLevel ++;
157 }
158
159<api_entry_param>{ID} {
160 memcpy(currType->name, yytext, yyleng);
Alex Sakhartchouk70b83c12011-04-06 10:57:51 -0700161 checkPointerType();
Jason Sams326e0dd2009-05-22 14:03:28 -0700162 BEGIN(api_entry2);
163 }
164
Jason Samsa2cf7552010-03-03 13:03:18 -0800165<api_entry2>"*" {
166 currType->ptrLevel ++;
167 }
Jason Sams326e0dd2009-05-22 14:03:28 -0700168
169<api_entry2>"}" {
170 apiCount++;
171 BEGIN(INITIAL);
172 }
173
174
175%%
176
177
178int yywrap()
179{
180 return 1;
181}
182