source: libabac/rt2.l @ efacf92

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

1) add hyphens as valid character in rolename and osetname

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