1 | %option stack |
---|
2 | %x BOOLEAN_S |
---|
3 | %x INTEGER_S |
---|
4 | %x FLOAT_S |
---|
5 | %x TIME_S |
---|
6 | %x URN_S |
---|
7 | %x STRING_S |
---|
8 | %x KEYID_S |
---|
9 | %x RANGE_S |
---|
10 | |
---|
11 | %top{ |
---|
12 | #include <stdio.h> |
---|
13 | #include <string.h> |
---|
14 | #include "rt2.h" |
---|
15 | |
---|
16 | static int debug=0; |
---|
17 | |
---|
18 | /* if using canned fixed test string */ |
---|
19 | char INPUT_LINE[] = "usc.playground <- usc.employee.friend"; |
---|
20 | char *yyfptr = INPUT_LINE; /* assigned with default */ |
---|
21 | char *yyfptr_encoded=NULL; |
---|
22 | |
---|
23 | /* with yacc */ |
---|
24 | extern YYSTYPE yylval; |
---|
25 | extern char* abac_encode_string(char *); |
---|
26 | |
---|
27 | #undef YY_INPUT |
---|
28 | #define YY_INPUT(buf,result,max_size) \ |
---|
29 | { \ |
---|
30 | if(yyfptr != NULL) { \ |
---|
31 | if(debug) printf("YY_INPUT, input max size is %d\n",max_size); \ |
---|
32 | char* c = strncpy(buf,yyfptr,max_size); \ |
---|
33 | if (max_size > 0) buf[max_size-1] = '\0'; \ |
---|
34 | if(strlen(yyfptr) > max_size) yyfptr = yyfptr + max_size-1; \ |
---|
35 | else yyfptr=NULL; \ |
---|
36 | result = (c == NULL ) ? YY_NULL : strlen(buf); \ |
---|
37 | if(debug) printf("YY_INPUT, buf size is %d\n",result); \ |
---|
38 | } else { \ |
---|
39 | buf[0] = '\0'; \ |
---|
40 | result = YY_NULL; \ |
---|
41 | } \ |
---|
42 | } |
---|
43 | |
---|
44 | } |
---|
45 | |
---|
46 | DIGIT [0-9] |
---|
47 | %% |
---|
48 | \. { if(debug) fprintf(yyout, " DOT " ); |
---|
49 | return DOT; } |
---|
50 | keyid { yylval.string=strdup(yytext); |
---|
51 | if(debug) fprintf(yyout," KEYTYPE "); |
---|
52 | return KEYTYPE; } |
---|
53 | <KEYID_S>[a-zA-Z0-9]+ { |
---|
54 | yylval.string=strdup(yytext); |
---|
55 | if(debug) fprintf(yyout," KEYID_CONSTANT "); |
---|
56 | return KEYID_CONSTANT; } |
---|
57 | oset { if(debug) fprintf(yyout," OSET "); |
---|
58 | return OSET; } |
---|
59 | role { if(debug) fprintf(yyout," ROLE "); |
---|
60 | return ROLE; } |
---|
61 | principal { if(debug) fprintf(yyout," PRINCIPAL "); |
---|
62 | return PRINCIPAL; } |
---|
63 | integer { yylval.string=strdup(yytext); |
---|
64 | if(debug) fprintf(yyout," OTYPE(INTEGER) "); |
---|
65 | return OTYPE; } |
---|
66 | <INTEGER_S>{DIGIT}+ { |
---|
67 | yylval.string=strdup(yytext); |
---|
68 | if(debug) fprintf(yyout," OTYPE_CONSTANT(INTEGER) "); |
---|
69 | return OTYPE_CONSTANT; } |
---|
70 | <INTEGER_S>[-]{DIGIT}+ { |
---|
71 | yylval.string=strdup(yytext); |
---|
72 | if(debug) fprintf(yyout," OTYPE_CONSTANT(INTEGER) "); |
---|
73 | return OTYPE_CONSTANT; } |
---|
74 | boolean { yylval.string =strdup(yytext); |
---|
75 | if(debug) fprintf(yyout," OTYPE(BOOLEAN) "); |
---|
76 | return OTYPE; } |
---|
77 | <BOOLEAN_S>true|false { |
---|
78 | yylval.string=strdup(yytext); |
---|
79 | if(debug) fprintf(yyout," OTYPE_CONSTANT(BOOLEAN) "); |
---|
80 | return OTYPE_CONSTANT; } |
---|
81 | <BOOLEAN_S,INTEGER_S,FLOAT_S,URN_S,STRING_S,TIME_S>[?][A-Z][\-_a-zA-Z0-9]* { |
---|
82 | yylval.string=strdup(yytext+1); |
---|
83 | if(debug) fprintf(yyout," VARIABLE_CONSTANT(%s) ",yylval.string); |
---|
84 | return VARIABLE_CONSTANT; } |
---|
85 | <BOOLEAN_S,INTEGER_S,FLOAT_S,URN_S,STRING_S,TIME_S>[?] { |
---|
86 | yylval.string=strdup(yytext+1); |
---|
87 | if(debug) fprintf(yyout," QMARK "); |
---|
88 | return QMARK; } |
---|
89 | <BOOLEAN_S,INTEGER_S,FLOAT_S,URN_S,STRING_S,TIME_S>\[ { |
---|
90 | if(debug) fprintf(yyout," LSQUARE "); |
---|
91 | return LSQUARE; } |
---|
92 | <BOOLEAN_S,INTEGER_S,FLOAT_S,URN_S,STRING_S,TIME_S>\] { |
---|
93 | if(debug) fprintf(yyout," RSQUARE "); |
---|
94 | return RSQUARE; } |
---|
95 | <BOOLEAN_S,INTEGER_S,FLOAT_S,URN_S,STRING_S,TIME_S>\: { |
---|
96 | if(debug) fprintf(yyout," COLON "); |
---|
97 | return COLON; } |
---|
98 | float { yylval.string =strdup(yytext); |
---|
99 | if(debug) fprintf(yyout," OTYPE(FLOAT) "); |
---|
100 | return OTYPE; } |
---|
101 | <FLOAT_S>-{DIGIT}+"."{DIGIT}+ | |
---|
102 | <FLOAT_S>{DIGIT}+"."{DIGIT}+ | |
---|
103 | <FLOAT_S>{DIGIT}+ | |
---|
104 | <FLOAT_S>-{DIGIT}+ { |
---|
105 | yylval.string=strdup(yytext); |
---|
106 | if(debug) fprintf(yyout," OTYPE_CONSTANT(FLOAT) "); |
---|
107 | return OTYPE_CONSTANT; } |
---|
108 | time { yylval.string=strdup(yytext); |
---|
109 | if(debug) fprintf(yyout," OTYPE(TIME) "); |
---|
110 | return OTYPE; } |
---|
111 | <TIME_S>{DIGIT}{DIGIT}*"T"{DIGIT}* { |
---|
112 | yylval.string=strdup(yytext); |
---|
113 | if(debug) fprintf(yyout," OTYPE_CONSTANT(TIME) "); |
---|
114 | return OTYPE_CONSTANT; } |
---|
115 | urn { yylval.string=strdup(yytext); |
---|
116 | if(debug) fprintf(yyout," OTYPE(URN) "); |
---|
117 | return OTYPE; } |
---|
118 | <URN_S>[']([^']|\\')*['] | |
---|
119 | <URN_S>["]([^"]|\")*["] { |
---|
120 | yylval.string=strdup(yytext); |
---|
121 | if(debug) fprintf(yyout," OTYPE_CONSTANT(URN)(%s) ",yylval.string); |
---|
122 | return OTYPE_CONSTANT; } |
---|
123 | string { yylval.string=strdup(yytext); |
---|
124 | if(debug) fprintf(yyout," OTYPE(STRING) "); |
---|
125 | return OTYPE; } |
---|
126 | <STRING_S>[']([^']|\\')*['] | |
---|
127 | <STRING_S>["]([^"]|\")*["] { |
---|
128 | yylval.string=strdup(yytext); |
---|
129 | if(debug) fprintf(yyout," OTYPE_CONSTANT(STRING)(%s) ", yylval.string); |
---|
130 | return OTYPE_CONSTANT; } |
---|
131 | <RANGE_S>\[ { |
---|
132 | if(debug) fprintf(yyout," LSQUARE "); |
---|
133 | return LSQUARE; } |
---|
134 | <RANGE_S>\] { |
---|
135 | if(debug) fprintf(yyout," RSQUARE "); |
---|
136 | return RSQUARE; } |
---|
137 | <RANGE_S>\.\. { |
---|
138 | if(debug) fprintf(yyout," DOTDOT "); |
---|
139 | return DOTDOT; } |
---|
140 | <RANGE_S>, { |
---|
141 | if(debug) fprintf(yyout," COMMA "); |
---|
142 | return COMMA; } |
---|
143 | <RANGE_S>true|false { |
---|
144 | yylval.string=strdup(yytext); |
---|
145 | if(debug) fprintf(yyout," VALUE(BOOLEAN)(%s) ", yylval.string); |
---|
146 | return VALUE; } |
---|
147 | <RANGE_S>[']([^']|\\')*['] | |
---|
148 | <RANGE_S>["]([^"]|\")*["] { |
---|
149 | yylval.string=strdup(yytext); |
---|
150 | if(debug) fprintf(yyout," VALUE(STRING)(%s) ", yylval.string); |
---|
151 | return VALUE; } |
---|
152 | <RANGE_S>{DIGIT}+ | |
---|
153 | <RANGE_S>-{DIGIT}+ | |
---|
154 | <RANGE_S>-{DIGIT}.{DIGIT}+ | |
---|
155 | <RANGE_S>{DIGIT}.{DIGIT}+ | |
---|
156 | <RANGE_S>{DIGIT}+T{DIGIT}+ { |
---|
157 | yylval.string=strdup(yytext); |
---|
158 | if(debug) fprintf(yyout," VALUE(%s) ",yylval.string); |
---|
159 | return VALUE; } |
---|
160 | [a-zA-Z0-9][\-_a-zA-Z0-9]* { |
---|
161 | yylval.string=strdup(yytext); |
---|
162 | if(debug) fprintf(yyout," IDEN(%s) ", yylval.string); |
---|
163 | return IDEN; } |
---|
164 | \<- { if(debug) fprintf(yyout," DERIVE "); |
---|
165 | return DERIVE; } |
---|
166 | & { if(debug) fprintf(yyout, " AND " ); |
---|
167 | return AND; } |
---|
168 | , { if(debug) fprintf(yyout, " COMMA "); |
---|
169 | return COMMA; } |
---|
170 | \( { if(debug) fprintf(yyout, " LPAREN "); |
---|
171 | return LPAREN; } |
---|
172 | \) { if(debug) fprintf(yyout, " RPAREN "); |
---|
173 | return RPAREN; } |
---|
174 | \[ { if(debug) fprintf(yyout, " LSQUARE "); |
---|
175 | return LSQUARE; } |
---|
176 | \] { if(debug) fprintf(yyout, " RSQUARE "); |
---|
177 | return RSQUARE; } |
---|
178 | \: { if(debug) fprintf(yyout, " COLON "); |
---|
179 | return COLON; } |
---|
180 | \? { if(debug) fprintf(yyout, " QMARK "); |
---|
181 | return QMARK; } |
---|
182 | \n { /* ignore end-of-line */; } |
---|
183 | [ \t]+ { /* ignore whitespace */; } |
---|
184 | %% |
---|
185 | |
---|
186 | void abac_reset_yyfptr(char *str) { |
---|
187 | yyfptr=str; |
---|
188 | yyfptr_encoded=abac_encode_string(str); |
---|
189 | } |
---|
190 | |
---|
191 | char* abac_get_yyfptr() { |
---|
192 | return yyfptr; |
---|
193 | } |
---|
194 | |
---|
195 | char *abac_get_yyfptr_encoded() { |
---|
196 | return yyfptr_encoded; |
---|
197 | } |
---|
198 | |
---|
199 | /* if using external file input, output */ |
---|
200 | void abac_reset_yyin(FILE *new_yyin) { |
---|
201 | yyin=new_yyin; |
---|
202 | } |
---|
203 | |
---|
204 | void abac_reset_yyout(FILE *new_yyout) { |
---|
205 | if(yyout) { |
---|
206 | fflush(yyout); |
---|
207 | fclose(yyout); |
---|
208 | } |
---|
209 | yyout=new_yyout; |
---|
210 | } |
---|
211 | |
---|
212 | void abac_flush_yyout() { |
---|
213 | if(yyout) |
---|
214 | fflush(yyout); |
---|
215 | } |
---|
216 | |
---|
217 | FILE *abac_get_yyin() { |
---|
218 | if(yyin) return yyin; |
---|
219 | else return stdin; |
---|
220 | } |
---|
221 | FILE *abac_get_yyout() { |
---|
222 | if(yyout) return yyout; |
---|
223 | else return stdout; |
---|
224 | } |
---|
225 | |
---|
226 | void abac_push_keyid_yystate() |
---|
227 | { |
---|
228 | if(debug) fprintf(yyout, "\n push keyid state\n"); |
---|
229 | yy_push_state(KEYID_S); |
---|
230 | } |
---|
231 | |
---|
232 | void abac_push_range_yystate() |
---|
233 | { |
---|
234 | if(debug) fprintf(yyout, "\n push range state\n"); |
---|
235 | yy_push_state(RANGE_S); |
---|
236 | } |
---|
237 | |
---|
238 | void abac_push_yystate(char *str) |
---|
239 | { |
---|
240 | if(strcmp(str,"boolean")==0) { |
---|
241 | if(debug) fprintf(yyout, "\n push boolean state\n"); |
---|
242 | yy_push_state(BOOLEAN_S); |
---|
243 | return; |
---|
244 | } |
---|
245 | if(strcmp(str,"integer")==0) { |
---|
246 | if(debug) fprintf(yyout, "\n push integer state\n"); |
---|
247 | yy_push_state(INTEGER_S); |
---|
248 | return; |
---|
249 | } |
---|
250 | if(strcmp(str,"float")==0) { |
---|
251 | if(debug) fprintf(yyout, "\n push float state\n"); |
---|
252 | yy_push_state(FLOAT_S); |
---|
253 | return; |
---|
254 | } |
---|
255 | if(strcmp(str,"time")==0) { |
---|
256 | if(debug) fprintf(yyout, "\n push time state\n"); |
---|
257 | yy_push_state(TIME_S); |
---|
258 | return; |
---|
259 | } |
---|
260 | if(strcmp(str,"urn")==0) { |
---|
261 | if(debug) fprintf(yyout, "\n push urn state\n"); |
---|
262 | yy_push_state(URN_S); |
---|
263 | return; |
---|
264 | } |
---|
265 | if(strcmp(str,"string")==0) { |
---|
266 | if(debug) fprintf(yyout, "\n push string state\n"); |
---|
267 | yy_push_state(STRING_S); |
---|
268 | return; |
---|
269 | } |
---|
270 | |
---|
271 | if(debug) fprintf(yyout, "eek.. lost in push_state\n"); |
---|
272 | } |
---|
273 | |
---|
274 | void abac_pop_yystate() |
---|
275 | { |
---|
276 | if(debug) fprintf(yyout, " pop a state\n"); |
---|
277 | yy_pop_state(); |
---|
278 | } |
---|