[da5afdf] | 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{ |
---|
[718ad924] | 12 | #include <stdio.h> |
---|
| 13 | #include <string.h> |
---|
| 14 | #include "rt2.h" |
---|
| 15 | |
---|
[e88c95b] | 16 | static int debug=0; |
---|
[718ad924] | 17 | |
---|
| 18 | /* if using canned fixed test string */ |
---|
| 19 | char INPUT_LINE[] = "usc.playground <- usc.employee.friend"; |
---|
[b5a3da4] | 20 | char *yyfptr = INPUT_LINE; /* assigned with default */ |
---|
[da5afdf] | 21 | char *yyfptr_encoded=NULL; |
---|
[b5a3da4] | 22 | |
---|
| 23 | /* with yacc */ |
---|
| 24 | extern YYSTYPE yylval; |
---|
[da5afdf] | 25 | extern char* abac_encode_string(char *); |
---|
[718ad924] | 26 | |
---|
| 27 | #undef YY_INPUT |
---|
| 28 | #define YY_INPUT(buf,result,max_size) \ |
---|
| 29 | { \ |
---|
| 30 | if(yyfptr != NULL) { \ |
---|
[669b481] | 31 | if(debug) printf("YY_INPUT, input max size is %d\n",max_size); \ |
---|
[718ad924] | 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); \ |
---|
[669b481] | 37 | if(debug) printf("YY_INPUT, buf size is %d\n",result); \ |
---|
[718ad924] | 38 | } else { \ |
---|
| 39 | buf[0] = '\0'; \ |
---|
| 40 | result = YY_NULL; \ |
---|
| 41 | } \ |
---|
| 42 | } |
---|
| 43 | |
---|
[da5afdf] | 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; } |
---|
[b5a3da4] | 53 | <KEYID_S>[a-zA-Z0-9]+ { |
---|
[da5afdf] | 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; } |
---|
[b5a3da4] | 66 | <INTEGER_S>{DIGIT}+ { |
---|
[da5afdf] | 67 | yylval.string=strdup(yytext); |
---|
| 68 | if(debug) fprintf(yyout," OTYPE_CONSTANT(INTEGER) "); |
---|
| 69 | return OTYPE_CONSTANT; } |
---|
[b5a3da4] | 70 | <INTEGER_S>[-]{DIGIT}+ { |
---|
[da5afdf] | 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; } |
---|
[efacf92] | 81 | <BOOLEAN_S,INTEGER_S,FLOAT_S,URN_S,STRING_S,TIME_S>[?][A-Z][\-_a-zA-Z0-9]* { |
---|
[da5afdf] | 82 | yylval.string=strdup(yytext+1); |
---|
| 83 | if(debug) fprintf(yyout," VARIABLE_CONSTANT(%s) ",yylval.string); |
---|
| 84 | return VARIABLE_CONSTANT; } |
---|
[9806e76] | 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; } |
---|
[da5afdf] | 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; } |
---|
[b5a3da4] | 101 | <FLOAT_S>-{DIGIT}+"."{DIGIT}+ | |
---|
| 102 | <FLOAT_S>{DIGIT}+"."{DIGIT}+ | |
---|
| 103 | <FLOAT_S>{DIGIT}+ | |
---|
| 104 | <FLOAT_S>-{DIGIT}+ { |
---|
[da5afdf] | 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; } |
---|
[d5bbd3e] | 140 | <RANGE_S>, { |
---|
| 141 | if(debug) fprintf(yyout," COMMA "); |
---|
| 142 | return COMMA; } |
---|
[4b8e1c9] | 143 | <RANGE_S>true|false { |
---|
| 144 | yylval.string=strdup(yytext); |
---|
| 145 | if(debug) fprintf(yyout," VALUE(BOOLEAN)(%s) ", yylval.string); |
---|
| 146 | return VALUE; } |
---|
[d5bbd3e] | 147 | <RANGE_S>[']([^']|\\')*['] | |
---|
| 148 | <RANGE_S>["]([^"]|\")*["] { |
---|
[c586a3c] | 149 | yylval.string=strdup(yytext); |
---|
| 150 | if(debug) fprintf(yyout," VALUE(STRING)(%s) ", yylval.string); |
---|
| 151 | return VALUE; } |
---|
[b5a3da4] | 152 | <RANGE_S>{DIGIT}+ | |
---|
| 153 | <RANGE_S>-{DIGIT}+ | |
---|
[c586a3c] | 154 | <RANGE_S>-{DIGIT}.{DIGIT}+ | |
---|
| 155 | <RANGE_S>{DIGIT}.{DIGIT}+ | |
---|
[b5a3da4] | 156 | <RANGE_S>{DIGIT}+T{DIGIT}+ { |
---|
[da5afdf] | 157 | yylval.string=strdup(yytext); |
---|
| 158 | if(debug) fprintf(yyout," VALUE(%s) ",yylval.string); |
---|
| 159 | return VALUE; } |
---|
[efacf92] | 160 | [a-zA-Z0-9][\-_a-zA-Z0-9]* { |
---|
[da5afdf] | 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 | |
---|
[718ad924] | 186 | void abac_reset_yyfptr(char *str) { |
---|
| 187 | yyfptr=str; |
---|
[da5afdf] | 188 | yyfptr_encoded=abac_encode_string(str); |
---|
[718ad924] | 189 | } |
---|
| 190 | |
---|
| 191 | char* abac_get_yyfptr() { |
---|
| 192 | return yyfptr; |
---|
| 193 | } |
---|
| 194 | |
---|
[da5afdf] | 195 | char *abac_get_yyfptr_encoded() { |
---|
| 196 | return yyfptr_encoded; |
---|
| 197 | } |
---|
| 198 | |
---|
[718ad924] | 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 | |
---|
[b5a3da4] | 226 | void abac_push_keyid_yystate() |
---|
[da5afdf] | 227 | { |
---|
| 228 | if(debug) fprintf(yyout, "\n push keyid state\n"); |
---|
| 229 | yy_push_state(KEYID_S); |
---|
| 230 | } |
---|
[718ad924] | 231 | |
---|
[b5a3da4] | 232 | void abac_push_range_yystate() |
---|
[da5afdf] | 233 | { |
---|
| 234 | if(debug) fprintf(yyout, "\n push range state\n"); |
---|
| 235 | yy_push_state(RANGE_S); |
---|
| 236 | } |
---|
| 237 | |
---|
[b5a3da4] | 238 | void abac_push_yystate(char *str) |
---|
[da5afdf] | 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 | |
---|
[b5a3da4] | 274 | void abac_pop_yystate() |
---|
[da5afdf] | 275 | { |
---|
| 276 | if(debug) fprintf(yyout, " pop a state\n"); |
---|
| 277 | yy_pop_state(); |
---|
| 278 | } |
---|