source: libabac/rt2.l @ b5a3da4

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

1) add abac_oset.c
2) reorganized some yyparse related files

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