source: libabac/rt2.l @ 4b8e1c9

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

1) add boolean static range constraint handling
2) add boolean range test into balltime_rt2_typed

  • Property mode set to 100644
File size: 8.1 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<RANGE_S>, {
135             if(debug) fprintf(yyout," COMMA ");
136             return COMMA; }
137<RANGE_S>true|false {
138             yylval.string=strdup(yytext);
139             if(debug) fprintf(yyout," VALUE(BOOLEAN)(%s) ", yylval.string);
140             return VALUE; }
141<RANGE_S>[']([^']|\\')*['] |
142<RANGE_S>["]([^"]|\")*["] {
143             yylval.string=strdup(yytext);
144             if(debug) fprintf(yyout," VALUE(STRING)(%s) ", yylval.string);
145             return VALUE; }
146<RANGE_S>{DIGIT}+ |
147<RANGE_S>-{DIGIT}+ |
148<RANGE_S>-{DIGIT}.{DIGIT}+ |
149<RANGE_S>{DIGIT}.{DIGIT}+ |
150<RANGE_S>{DIGIT}+T{DIGIT}+ {
151             yylval.string=strdup(yytext);
152             if(debug) fprintf(yyout," VALUE(%s) ",yylval.string);
153             return VALUE; }
154[a-zA-Z0-9][_a-zA-Z0-9]* {
155             yylval.string=strdup(yytext);
156             if(debug) fprintf(yyout," IDEN(%s) ", yylval.string);
157             return IDEN; }
158\<-          { if(debug) fprintf(yyout," DERIVE ");
159             return DERIVE; }
160&            { if(debug) fprintf(yyout, " AND " );
161             return AND; }
162,            { if(debug) fprintf(yyout, " COMMA ");
163             return COMMA; }
164\(           { if(debug) fprintf(yyout, " LPAREN ");
165             return LPAREN; }
166\)           { if(debug) fprintf(yyout, " RPAREN ");
167             return RPAREN; }
168\[           { if(debug) fprintf(yyout, " LSQUARE ");
169             return LSQUARE; }
170\]           { if(debug) fprintf(yyout, " RSQUARE ");
171             return RSQUARE; }
172\:           { if(debug) fprintf(yyout, " COLON ");
173             return COLON; }
174\?           { if(debug) fprintf(yyout, " QMARK ");
175             return QMARK; }
176\n           { /* ignore end-of-line */; }
177[ \t]+       { /* ignore whitespace */; }
178%%
179
180void abac_reset_yyfptr(char *str) {
181    yyfptr=str;
182    yyfptr_encoded=abac_encode_string(str);
183}
184
185char* abac_get_yyfptr() {
186    return yyfptr;
187}
188
189char *abac_get_yyfptr_encoded() {
190    return yyfptr_encoded;
191}
192
193/* if using external file input, output */
194void abac_reset_yyin(FILE *new_yyin) {
195    yyin=new_yyin;
196}
197
198void abac_reset_yyout(FILE *new_yyout) {
199    if(yyout) {
200      fflush(yyout);
201      fclose(yyout);
202    }
203    yyout=new_yyout;
204}
205
206void abac_flush_yyout() {
207    if(yyout)
208      fflush(yyout);
209}
210
211FILE *abac_get_yyin() {
212    if(yyin) return yyin;
213    else return stdin;
214}
215FILE *abac_get_yyout() {
216    if(yyout) return yyout;
217    else return stdout;
218}
219
220void abac_push_keyid_yystate()
221{
222    if(debug) fprintf(yyout, "\n push keyid state\n");
223    yy_push_state(KEYID_S);
224}
225
226void abac_push_range_yystate()
227{
228    if(debug) fprintf(yyout, "\n push range state\n");
229    yy_push_state(RANGE_S);
230}
231
232void abac_push_yystate(char *str)
233{
234   if(strcmp(str,"boolean")==0) {
235      if(debug) fprintf(yyout, "\n push boolean state\n");
236      yy_push_state(BOOLEAN_S);
237      return;
238   }
239   if(strcmp(str,"integer")==0) {
240      if(debug) fprintf(yyout, "\n push integer state\n");
241      yy_push_state(INTEGER_S);
242      return;
243   }
244   if(strcmp(str,"float")==0) {
245      if(debug) fprintf(yyout, "\n push float state\n");
246      yy_push_state(FLOAT_S);
247      return;
248   }
249   if(strcmp(str,"time")==0) {
250      if(debug) fprintf(yyout, "\n push time state\n");
251      yy_push_state(TIME_S);
252      return;
253   }
254   if(strcmp(str,"urn")==0) {
255      if(debug) fprintf(yyout, "\n push urn state\n");
256      yy_push_state(URN_S);
257      return;
258   }
259   if(strcmp(str,"string")==0) {
260      if(debug) fprintf(yyout, "\n push string state\n");
261      yy_push_state(STRING_S);
262      return;
263   }
264   
265   if(debug) fprintf(yyout, "eek.. lost in push_state\n");
266}
267
268void abac_pop_yystate()
269{
270   if(debug) fprintf(yyout, " pop a state\n");
271   yy_pop_state();
272}
Note: See TracBrowser for help on using the repository browser.