source: libabac/rt2.l @ da5afdf

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

1) add static contraint

(limited to integer at this time)

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