blob: 62fcb63524e25e39d5e261819dc61ad55dd85815 [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
Joe Onorato84614dd2009-08-10 15:01:51 -070023 extern "C" int yylex();
24
Jason Sams326e0dd2009-05-22 14:03:28 -070025%%
26
27"/*" BEGIN(comment);
28<comment>[^*\n]* /* eat anything that's not a '*' */
29<comment>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */
30<comment>\n ++num_lines;
31<comment>"*"+"/" BEGIN(INITIAL);
32
33<*>" " //printf("found ' '\n");
34<*>"\n" ++num_lines; //printf("found lf \n");
35
36{ID} {
37 memset(&apis[apiCount], 0, sizeof(ApiEntry));
38 memcpy(apis[apiCount].name, yytext, yyleng);
39 BEGIN(api_entry);
40 }
41
42<api_entry>"{" {
43 BEGIN(api_entry2);
44 }
45
46<api_entry2>"sync" {
47 apis[apiCount].sync = 1;
48 }
49
50<api_entry2>"ret" {
51 currType = &apis[apiCount].ret;
52 typeNextState = api_entry2;
53 BEGIN(var_type);
54 }
55
56<api_entry2>"param" {
57 currType = &apis[apiCount].params[apis[apiCount].paramCount];
58 apis[apiCount].paramCount++;
59 typeNextState = api_entry_param;
60 BEGIN(var_type);
61 }
62
63<var_type>"const" {
64 currType->isConst = 1;
65 }
66
67<var_type>"i8" {
68 currType->type = 1;
69 currType->bits = 8;
70 BEGIN(typeNextState);
71 }
72
73<var_type>"i16" {
74 currType->type = 1;
75 currType->bits = 16;
76 BEGIN(typeNextState);
77 }
78
79<var_type>"i32" {
80 currType->type = 1;
81 currType->bits = 32;
82 BEGIN(typeNextState);
83 }
84
85<var_type>"i64" {
86 currType->type = 1;
87 currType->bits = 64;
88 BEGIN(typeNextState);
89 }
90
91<var_type>"u8" {
92 currType->type = 2;
93 currType->bits = 8;
94 BEGIN(typeNextState);
95 }
96
97<var_type>"u16" {
98 currType->type = 2;
99 currType->bits = 16;
100 BEGIN(typeNextState);
101 }
102
103<var_type>"u32" {
104 currType->type = 2;
105 currType->bits = 32;
106 BEGIN(typeNextState);
107 }
108
109<var_type>"u64" {
110 currType->type = 2;
111 currType->bits = 64;
112 BEGIN(typeNextState);
113 }
114
115<var_type>"f" {
116 currType->type = 3;
117 currType->bits = 32;
118 BEGIN(typeNextState);
119 }
120
121<var_type>"d" {
122 currType->type = 3;
123 currType->bits = 64;
124 BEGIN(typeNextState);
125 }
126
127<var_type>{ID} {
128 currType->type = 4;
129 currType->bits = 32;
Joe Onorato84614dd2009-08-10 15:01:51 -0700130 memcpy(currType->typeName, yytext, yyleng);
Jason Sams326e0dd2009-05-22 14:03:28 -0700131 BEGIN(typeNextState);
132 }
133
134<api_entry_param>"*" {
135 currType->ptrLevel ++;
136 }
137
138<api_entry_param>{ID} {
139 memcpy(currType->name, yytext, yyleng);
140 BEGIN(api_entry2);
141 }
142
143
144<api_entry2>"}" {
145 apiCount++;
146 BEGIN(INITIAL);
147 }
148
149
150%%
151
152
153int yywrap()
154{
155 return 1;
156}
157