Index: libabac/ort0.y
===================================================================
--- libabac/ort0.y	(revision e95d652a2cd6131b110bcb0e946047818f4fe954)
+++ libabac/ort0.y	(revision e95d652a2cd6131b110bcb0e946047818f4fe954)
@@ -0,0 +1,155 @@
+
+
+/* bison grammar rules for process old rt0 statements */
+/*
+   isi.employee <- ted
+   ted.friend <- mike
+   usc.employee <- isi.employee
+   usc.playground <- usc.employee.friend
+   query,
+      usc.playground <- ?Z
+      isi.playground <- mike
+*/
+
+%{
+/* C declarations */
+#include <stdio.h>
+#include <string.h>
+#include <abac_stack.h>
+
+extern char *abac_cn_with_sha(char*);
+
+FILE *abac_yyin = NULL;
+FILE *abac_yyout = NULL;
+char *abac_yap_clause = NULL;
+char *abac_yyfptr = NULL;
+char *tmp_cred_list = NULL;
+
+int sz_overhead = 0;
+
+%}
+/* Bison declarations */
+%union {
+int  number;
+char *string;   /* For returning char strings */
+}
+%type <string> keypart rolepart left right stmt
+
+%token <string> IDEN       /* keyname or rolename */
+
+%token  <operator>  DERIVE    "<-"
+%token  <operator>  DOT       "."
+
+%%
+/* Grammar rules */
+
+input:      /* empty */
+             { }
+        | stmt 
+             { fprintf (abac_yyout,"stmt (%s)\n", $1);
+               abac_yap_clause = $1;
+             }
+ 
+stmt : left DERIVE right
+             { int sz;
+               char *ptr=strstr($3,"role(");
+               char *tmp;
+               if(ptr==NULL) {
+                 sz=strlen($3)+strlen($1)+sz_overhead;
+                 tmp=(char *)abac_xmalloc(sz);
+                 printf("before.. (%s)\n", $3);
+                 sprintf(tmp,"isMember(%s,%s,['%s'])",$3,$1,abac_yyfptr);
+                 printf("after.. (%s)\n", tmp);
+               } else {
+                 sz=strlen($3)+strlen($1)+sz_overhead;
+                 tmp=(char *)abac_xmalloc(sz);
+                 if (tmp_cred_list==NULL) { 
+                     sprintf(tmp,"isMember(X,%s,['%s']):-%s",
+                                        $1, abac_yyfptr, $3);
+                     } else {
+                     sprintf(tmp,"isMember(X,%s,['%s',%s]):-%s",
+                                        $1, abac_yyfptr, tmp_cred_list, $3);
+                     free(tmp_cred_list);
+                     tmp_cred_list=NULL;
+                 }
+               }
+               $$=tmp;
+               free($3);free($1);
+             }
+
+left : keypart DOT rolepart
+             { 
+               int sz=strlen($1)+strlen($3)+sz_overhead;
+               char *tmp=(char *)abac_xmalloc(sz);
+               sprintf(tmp,"role(%s,%s)", $1, $3);
+               $$=tmp; 
+               free($3);free($1);
+             }
+/* isi */
+keypart : IDEN 
+             { 
+             char *cn=abac_cn_with_sha($1);
+             $$=strdup(cn);
+             }
+
+/* friend */
+rolepart : IDEN
+             { $$=strdup($1); }
+
+right : keypart DOT IDEN DOT IDEN
+             { 
+               int sz=strlen($1)+strlen($3)+strlen($5)+sz_overhead;
+               char *tmp=(char *)abac_xmalloc(sz);
+               sprintf(tmp,"isMember(Y,role(%s,%s),[C1]),isMember(X,role(Y,%s),[C2])",$1,$3,$5);
+               tmp_cred_list = strdup("C1,C2");
+               $$=tmp; 
+               free($1);free($3);free($5);
+             }
+      | keypart DOT IDEN
+             { 
+               int sz=strlen($1)+strlen($3)+sz_overhead;
+               char *tmp=(char *)abac_xmalloc(sz);
+               sprintf(tmp,"isMember(X,role(%s,%s),[C1])", $1, $3);
+               tmp_cred_list = strdup("C1");
+               $$=tmp; 
+               free($1);free($3);
+             }
+      | keypart
+             { 
+             $$=$1;
+             }
+
+%%
+#include "abac_rt0.h"
+
+/* Additional C code */
+int yywrap()
+{
+     /* exit when done lexing the current input */
+     return 1;
+} 
+
+int yyerror (char *s)
+{
+     fprintf (abac_yyout,"yyerror: %s\n", s);
+}
+
+/* setting defaults */
+void abac_yyinit()
+{
+    abac_yyin=abac_get_yyin();
+    abac_yyout=abac_get_yyout();
+    abac_yyfptr = abac_get_yyfptr();
+    sz_overhead = strlen(abac_yyfptr)+2000;
+} 
+
+char *abac_get_yap_clause()
+{
+    return abac_yap_clause;
+}
+
+char *abac_free_yap_clause()
+{
+    if (abac_yap_clause != NULL)
+        free(abac_yap_clause);
+}
