%{ #include #include #include "rt2.h" static int debug=0; /* with yacc */ extern YYSTYPE yylval; /* with just lex */ /* YYSTYPE yylval; */ /* if using canned fixed test string */ char INPUT_LINE[] = "usc.playground <- usc.employee.friend"; char *yyfptr = INPUT_LINE; /* default */ #undef YY_INPUT #define YY_INPUT(buf,result,max_size) \ { \ if(yyfptr != NULL) { \ char* c = strncpy(buf,yyfptr,max_size); \ if (max_size > 0) buf[max_size-1] = '\0'; \ if(strlen(yyfptr) > max_size) yyfptr = yyfptr + max_size-1; \ else yyfptr=NULL; \ result = (c == NULL ) ? YY_NULL : strlen(buf); \ } else { \ buf[0] = '\0'; \ result = YY_NULL; \ } \ } void abac_reset_yyfptr(char *str) { yyfptr=str; } char* abac_get_yyfptr() { return yyfptr; } /* if using external file input, output */ void abac_reset_yyin(FILE *new_yyin) { yyin=new_yyin; } void abac_reset_yyout(FILE *new_yyout) { if(yyout) { fflush(yyout); fclose(yyout); } yyout=new_yyout; } void abac_flush_yyout() { if(yyout) fflush(yyout); } FILE *abac_get_yyin() { if(yyin) return yyin; else return stdin; } FILE *abac_get_yyout() { if(yyout) return yyout; else return stdout; } /* XXX need to add param's possible format and break it out from IDEN next */ %} %% keyid { yylval.string=strdup(yytext); if(debug) fprintf(yyout," KEYTYPE "); return KEYTYPE; } role { if(debug) fprintf(yyout," ROLE "); return ROLE; } principal { if(debug) fprintf(yyout," PRINCIPAL "); return PRINCIPAL; } [a-zA-Z0-9][_a-zA-Z0-9]* { yylval.string=strdup(yytext); if(debug) fprintf(yyout," IDEN "); return IDEN; } \<- { if(debug) fprintf(yyout," DERIVE "); return DERIVE; } \. { if(debug) fprintf(yyout, " DOT " ); return DOT; } & { if(debug) fprintf(yyout, " AND " ); return AND; } , { if(debug) fprintf(yyout, " COMMA "); return COMMA; } \( { if(debug) fprintf(yyout, " LPAREN "); return LPAREN; } \) { if(debug) fprintf(yyout, " RPAREN "); return RPAREN; } \[ { if(debug) fprintf(yyout, " LSQUARE "); return LSQUARE; } \] { if(debug) fprintf(yyout, " RSQUARE "); return RSQUARE; } \: { if(debug) fprintf(yyout, " COLON "); return COLON; } \? { if(debug) fprintf(yyout, " QMARK "); return QMARK; } \n { /* ignore end-of-line */; } [ \t]+ { /* ignore whitespace */; } %%