Index: libabac/rt2.l
===================================================================
--- libabac/rt2.l	(revision 718ad9243faff3a00dea5c5c5b2ef6fe89caedbe)
+++ libabac/rt2.l	(revision da5afdf4d61c978dbd17b9d6f20e5a45dcab870a)
@@ -1,8 +1,18 @@
-%{
+%option stack
+%x BOOLEAN_S
+%x INTEGER_S 
+%x FLOAT_S
+%x TIME_S
+%x URN_S
+%x STRING_S
+%x KEYID_S
+%x RANGE_S
+
+%top{
 #include <stdio.h>
 #include <string.h>
 #include "rt2.h"
 
-static int debug=0;
+static int debug=1;
 
 /* with yacc */
@@ -14,4 +24,8 @@
 char INPUT_LINE[] = "usc.playground <- usc.employee.friend";
 char *yyfptr = INPUT_LINE; /* default */
+char *yyfptr_encoded=NULL;
+static void yy_push_state(int);
+static void yy_pop_state();
+extern char* abac_encode_string(char *);
 
 #undef YY_INPUT
@@ -30,10 +44,145 @@
     }
 
+}
+
+DIGIT    [0-9]
+ID	 [a-z][a-z0-9]*
+
+%%
+\.           { if(debug) fprintf(yyout, " DOT " );
+             return DOT; }
+keyid        { yylval.string=strdup(yytext);
+             if(debug) fprintf(yyout," KEYTYPE ");
+             return KEYTYPE; }
+<KEYID_S>[a-zA-Z0-9][a-zA-Z0-9]* {
+             yylval.string=strdup(yytext);
+             if(debug) fprintf(yyout," KEYID_CONSTANT ");
+             return KEYID_CONSTANT; }
+oset         { if(debug) fprintf(yyout," OSET ");
+             return OSET; }
+role         { if(debug) fprintf(yyout," ROLE ");
+             return ROLE; }
+principal    { if(debug) fprintf(yyout," PRINCIPAL ");
+             return PRINCIPAL; }
+integer      { yylval.string=strdup(yytext);
+             if(debug) fprintf(yyout," OTYPE(INTEGER) ");
+             return OTYPE; }
+<INTEGER_S>[0-9]+ {
+             yylval.string=strdup(yytext);
+             if(debug) fprintf(yyout," OTYPE_CONSTANT(INTEGER) ");
+             return OTYPE_CONSTANT; }
+<INTEGER_S>[-][0-9]+ { 
+             yylval.string=strdup(yytext);
+             if(debug) fprintf(yyout," OTYPE_CONSTANT(INTEGER) ");
+             return OTYPE_CONSTANT; }
+boolean      { yylval.string =strdup(yytext);
+             if(debug) fprintf(yyout," OTYPE(BOOLEAN) ");
+             return OTYPE; }
+<BOOLEAN_S>true|false {
+             yylval.string=strdup(yytext);
+             if(debug) fprintf(yyout," OTYPE_CONSTANT(BOOLEAN) ");
+             return OTYPE_CONSTANT; }
+<BOOLEAN_S,INTEGER_S,FLOAT_S,URN_S,STRING_S,TIME_S>[?][A-Z][_a-zA-Z0-9]* { 
+             yylval.string=strdup(yytext+1);
+             if(debug) fprintf(yyout," VARIABLE_CONSTANT(%s) ",yylval.string);
+             return VARIABLE_CONSTANT; }
+<BOOLEAN_S,INTEGER_S,FLOAT_S,URN_S,STRING_S,TIME_S>\[ { 
+             if(debug) fprintf(yyout," LSQUARE ");
+             return LSQUARE; }
+<BOOLEAN_S,INTEGER_S,FLOAT_S,URN_S,STRING_S,TIME_S>\] { 
+             if(debug) fprintf(yyout," RSQUARE ");
+             return RSQUARE; }
+<BOOLEAN_S,INTEGER_S,FLOAT_S,URN_S,STRING_S,TIME_S>\: { 
+             if(debug) fprintf(yyout," COLON ");
+             return COLON; }
+float        { yylval.string =strdup(yytext);
+             if(debug) fprintf(yyout," OTYPE(FLOAT) ");
+             return OTYPE; }
+<FLOAT_S>-[0-9]+"."[0-9]+ | 
+<FLOAT_S>[0-9]+"."[0-9]+ |
+<FLOAT_S>[0-9]+ |
+<FLOAT_S>-[0-9]+ {
+             yylval.string=strdup(yytext);
+             if(debug) fprintf(yyout," OTYPE_CONSTANT(FLOAT) ");
+             return OTYPE_CONSTANT; }
+time         { yylval.string=strdup(yytext);
+             if(debug) fprintf(yyout," OTYPE(TIME) ");
+             return OTYPE; }
+<TIME_S>{DIGIT}{DIGIT}*"T"{DIGIT}* {
+             yylval.string=strdup(yytext);
+             if(debug) fprintf(yyout," OTYPE_CONSTANT(TIME) ");
+             return OTYPE_CONSTANT; }
+urn          { yylval.string=strdup(yytext);
+             if(debug) fprintf(yyout," OTYPE(URN) ");
+             return OTYPE; }
+<URN_S>[']([^']|\\')*['] |
+<URN_S>["]([^"]|\")*["] {
+             yylval.string=strdup(yytext); 
+             if(debug) fprintf(yyout," OTYPE_CONSTANT(URN)(%s) ",yylval.string);
+             return OTYPE_CONSTANT; }
+string       { yylval.string=strdup(yytext);
+             if(debug) fprintf(yyout," OTYPE(STRING) ");
+             return OTYPE; }
+<STRING_S>[']([^']|\\')*['] |
+<STRING_S>["]([^"]|\")*["] {
+             yylval.string=strdup(yytext); 
+             if(debug) fprintf(yyout," OTYPE_CONSTANT(STRING)(%s) ", yylval.string);
+             return OTYPE_CONSTANT; }
+<RANGE_S>\[ { 
+             if(debug) fprintf(yyout," LSQUARE ");
+             return LSQUARE; }
+<RANGE_S>\] { 
+             if(debug) fprintf(yyout," RSQUARE ");
+             return RSQUARE; }
+<RANGE_S>\.\. { 
+             if(debug) fprintf(yyout," DOTDOT ");
+             return DOTDOT; }
+<RANGE_S>[0-9]+ | 
+<RANGE_S>-[0-9]+ |
+<RANGE_S>[0-9]+T[0-9]+ {
+             yylval.string=strdup(yytext);
+             if(debug) fprintf(yyout," VALUE(%s) ",yylval.string);
+             return VALUE; }
+[a-zA-Z0-9][_a-zA-Z0-9]* { 
+             yylval.string=strdup(yytext); 
+             if(debug) fprintf(yyout," IDEN(%s) ", yylval.string);
+             return IDEN; }
+\<-          { if(debug) fprintf(yyout," DERIVE ");
+             return DERIVE; }
+&            { 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, " LWIGGLE ");
+             return LWIGGLE; }
+\}           { if(debug) fprintf(yyout, " RWIGGLE ");
+             return RWIGGLE; }
+\:           { if(debug) fprintf(yyout, " COLON ");
+             return COLON; }
+\?           { if(debug) fprintf(yyout, " QMARK ");
+             return QMARK; }
+\n           { /* ignore end-of-line */; }
+[ \t]+       { /* ignore whitespace */; }
+%%
+
 void abac_reset_yyfptr(char *str) {
     yyfptr=str;
+    yyfptr_encoded=abac_encode_string(str);
 }
 
 char* abac_get_yyfptr() {
     return yyfptr;
+}
+
+char *abac_get_yyfptr_encoded() {
+    return yyfptr_encoded;
 }
 
@@ -65,39 +214,68 @@
 }
 
-/* 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 */; }
-%%
-
+void abac_yy_push_keyid_state()
+{
+    if(debug) fprintf(yyout, "\n push keyid state\n");
+    yy_push_state(KEYID_S);
+}
+
+void abac_yy_push_range_state()
+{
+    if(debug) fprintf(yyout, "\n push range state\n");
+    yy_push_state(RANGE_S);
+}
+
+char* abac_yy_get_state_string(int t)
+{
+    switch (t) {
+     case BOOLEAN_S: return strdup("boolean");
+     case INTEGER_S: return strdup("integer");
+     case FLOAT_S: return strdup("float");
+     case TIME_S: return strdup("time");
+     case URN_S: return strdup("urn");
+     case STRING_S: return strdup("string");
+     default: return strdup("dumdum");
+   }
+}
+
+void abac_yy_push_state(char *str)
+{
+   if(strcmp(str,"boolean")==0) {
+      if(debug) fprintf(yyout, "\n push boolean state\n");
+      yy_push_state(BOOLEAN_S);
+      return;
+   }
+   if(strcmp(str,"integer")==0) {
+      if(debug) fprintf(yyout, "\n push integer state\n");
+      yy_push_state(INTEGER_S);
+      return;
+   }
+   if(strcmp(str,"float")==0) {
+      if(debug) fprintf(yyout, "\n push float state\n");
+      yy_push_state(FLOAT_S);
+      return;
+   }
+   if(strcmp(str,"time")==0) {
+      if(debug) fprintf(yyout, "\n push time state\n");
+      yy_push_state(TIME_S);
+      return;
+   }
+   if(strcmp(str,"urn")==0) {
+      if(debug) fprintf(yyout, "\n push urn state\n");
+      yy_push_state(URN_S);
+      return;
+   }
+   if(strcmp(str,"string")==0) {
+      if(debug) fprintf(yyout, "\n push string state\n");
+      yy_push_state(STRING_S);
+      return;
+   }
+   
+   if(debug) fprintf(yyout, "eek.. lost in push_state\n");
+}
+
+void abac_yy_pop_state()
+{
+   if(debug) fprintf(yyout, " pop a state\n");
+   yy_pop_state();
+}
