source: libabac/rt2.l @ c586a3c

mei_rt2mei_rt2_fix_1meiyap-rt1rt2
Last change on this file since c586a3c was c586a3c, checked in by Mei <mei@…>, 12 years ago

1) add support for float static range constraint
2) add a testcase for testing float static range constraint
3) add runall-fast (skipping the creddy part)

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