# include "stdio.h" #ifdef __cplusplus extern "C" { extern int yyreject(); extern int yywrap(); extern int yylook(); extern void main(); extern int yyback(int *, int); extern int yyinput(); extern void yyoutput(int); extern void yyunput(int); extern int yylex(); } #endif /* __cplusplus */ # define U(x) x # define NLSTATE yyprevious=YYNEWLINE # define BEGIN yybgin = yysvec + 1 + # define INITIAL 0 # define YYLERR yysvec # define YYSTATE (yyestate-yysvec-1) # define YYOPTIM 1 # define YYLMAX 200 # define output(c) putc(c,yyout) # define input() (((yytchar=yysptr>yysbuf?U(*--yysptr):getc(yyin))==10?(yylineno++,yytchar):yytchar)==EOF?0:yytchar) # define unput(c) {yytchar= (c);if(yytchar=='\n')yylineno--;*yysptr++=yytchar;} # define yymore() (yymorfg=1) # define ECHO fprintf(yyout, "%s",yytext) # define REJECT { nstr = yyreject(); goto yyfussy;} int yyleng; extern unsigned char yytext[]; int yymorfg; extern unsigned char *yysptr, yysbuf[]; int yytchar; FILE *yyin = {stdin}, *yyout = {stdout}; extern int yylineno; struct yysvf { int yystoff; struct yysvf *yyother; int *yystops;}; struct yysvf *yyestate; extern struct yysvf yysvec[], *yybgin; char temp[40]; int i, j; int var_counter=0; void reset_var_table(); void extract_agent_name(char *yytext); int lookup_term(char *yytext); int lookup_var(char *yytext); # define YYNEWLINE 10 yylex(){ int nstr; extern int yyprevious; while((nstr = yylook()) >= 0) yyfussy: switch(nstr){ case 0: if(yywrap()) return(0); break; case 1: ; break; case 2: ; break; case 3: ; break; case 4: ; break; case 5: {yyless(yyleng -1); return(P_MODULE);} break; case 6: {yyless(yyleng -1); return(P_ABDUCIBLE);} break; case 7: {yyless(yyleng -1); return(P_RECURSIVE);} break; case 8: return(P_FORWARD); break; case 9: return(P_D_FORWARD); break; case 10: return(P_BACKWARD); break; case 11: return(P_DIRECT); break; case 12: { yylval.ival = lookup_var(yytext); return(P_VARIABLE); } break; case 13: { yylval.ival = lookup_term(yytext); return(P_ATOM); } break; case 14: return(P_COMMA); break; case 15: { yylval.ival = var_counter; reset_var_table(); return(P_PERIOD); } break; case 16: { j = 0; for(i=1; iname,string)!=0) i++; if (i= max_sym_size -1){ /* Increase the size of the symbole table.*/ temp = realloc((void *)sym_table, sizeof(functor *)* (max_sym_size + BLOCK_SIZE)); if(temp == NULL) {printf("Unable to increase the symbol table.\n"); exit(1);} max_sym_size += BLOCK_SIZE; sym_table = (functor **)temp; } sym_table[term_counter] = (functor *) my_alloc(sizeof(functor)); strcpy(sym_table[term_counter]->name, yytext); sym_table[term_counter]->type = 'N'; sym_table[term_counter]->agent_ref = NULL; i = term_counter++; } return(i); } /***************************************************/ /* Look for the string in the table. */ /* Insert if not found */ /***************************************************/ int lookup_var(char *yytext) { int i=0; int found =0; while((i< var_counter) && !found) if(strcmp(var_table[i], yytext) == 0) found = 1; else i++; if(!found){ var_table[var_counter] = (char *)my_alloc(20*sizeof(char)); strcpy(var_table[var_counter], yytext); i = var_counter++; } return(i); } int yyvstop[] = { 0, 4, 0, 4, 0, 19, 0, 3, 19, 0, 2, 0, 4, 19, 0, 19, 0, 19, 0, 19, 0, 14, 19, 0, 19, 0, 15, 19, 0, 17, 19, 0, 19, 0, 19, 0, 12, 19, 0, 13, 19, 0, 13, 19, 0, 13, 19, 0, 4, 0, 18, 0, 1, 0, 16, 0, 9, 0, 8, 0, 17, 0, 11, 0, 10, 0, 12, 0, 13, 0, 13, 0, 13, 0, 13, 0, 13, 0, 13, 0, 13, 0, 13, 0, 13, 0, 13, 0, 13, 0, 13, 0, 13, 0, 13, 0, 13, 0, 13, 0, 13, 0, 13, 0, 13, 0, 13, 0, 13, 0, 13, 0, 13, 0, 13, 0, 13, 0, 13, 0, 13, 0, 6, 0, 13, 0, 7, 0, 5, 0, 0}; # define YYTYPE unsigned char struct yywork { YYTYPE verify, advance; } yycrank[] = { 0,0, 0,0, 1,3, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 1,4, 1,5, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 1,6, 6,20, 1,7, 2,4, 15,31, 1,8, 0,0, 1,9, 0,0, 0,0, 0,0, 0,0, 1,10, 1,11, 1,12, 14,30, 1,13, 15,32, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 1,14, 0,0, 1,15, 0,0, 11,27, 2,8, 1,3, 1,16, 11,28, 0,0, 0,0, 0,0, 2,10, 2,11, 2,12, 13,29, 13,29, 13,29, 13,29, 13,29, 13,29, 13,29, 13,29, 13,29, 13,29, 0,0, 2,14, 0,0, 2,15, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 1,3, 0,0, 1,17, 1,18, 1,18, 1,18, 1,18, 1,18, 1,18, 1,18, 1,18, 1,18, 1,18, 1,18, 1,18, 1,18, 1,18, 1,18, 1,18, 1,19, 1,18, 1,18, 1,18, 1,18, 1,18, 1,18, 1,18, 1,18, 0,0, 2,18, 2,18, 2,18, 2,18, 2,18, 2,18, 2,18, 2,18, 2,18, 2,18, 2,18, 2,18, 2,18, 2,18, 2,18, 2,18, 2,19, 2,18, 2,18, 2,18, 2,18, 2,18, 2,18, 2,18, 2,18, 7,21, 0,0, 18,34, 8,23, 0,0, 19,34, 9,25, 18,34, 19,38, 7,21, 19,34, 34,34, 8,24, 0,0, 0,0, 9,25, 34,34, 36,34, 37,34, 36,40, 0,0, 37,41, 36,34, 37,34, 38,34, 38,42, 0,0, 40,34, 0,0, 38,34, 41,34, 7,21, 40,34, 7,22, 8,23, 41,34, 8,23, 9,25, 7,21, 9,25, 42,34, 8,23, 41,44, 44,34, 9,26, 42,34, 40,43, 7,21, 44,34, 45,34, 8,23, 43,34, 43,46, 9,25, 45,34, 46,34, 43,34, 0,0, 0,0, 42,45, 46,34, 44,47, 46,49, 7,21, 7,21, 45,48, 8,23, 8,23, 47,50, 9,25, 9,25, 47,34, 48,34, 49,52, 50,34, 51,34, 47,34, 48,34, 49,34, 50,34, 51,34, 0,0, 51,54, 52,34, 53,56, 53,34, 50,53, 56,34, 52,34, 48,51, 53,34, 0,0, 56,34, 52,55, 7,21, 0,0, 7,21, 8,23, 56,59, 8,23, 9,25, 0,0, 9,25, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 55,34, 57,34, 0,0, 55,58, 57,60, 55,34, 57,34, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 59,34, 0,0, 0,0, 59,62, 16,33, 59,34, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 16,33, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 17,35, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 0,0, 0,0, 0,0, 0,0, 17,34, 0,0, 17,34, 17,36, 17,34, 17,34, 17,34, 17,34, 17,37, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 17,34, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 0,0, 0,0, 0,0, 0,0, 35,39, 0,0, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 35,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 58,61, 60,63, 62,64, 0,0, 39,39, 0,0, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 39,39, 54,34, 0,0, 0,0, 0,0, 0,0, 54,34, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 54,57, 0,0, 0,0, 0,0, 0,0, 0,0, 58,34, 60,34, 62,34, 0,0, 0,0, 58,34, 60,34, 62,34, 0,0, 0,0}; struct yysvf yysvec[] = { 0, 0, 0, -1, 0, yyvstop+1, -27, yysvec+1, yyvstop+3, 0, 0, yyvstop+5, 0, 0, yyvstop+7, 0, 0, yyvstop+10, 2, 0, yyvstop+12, -149, 0, yyvstop+15, -152, 0, yyvstop+17, -155, 0, yyvstop+19, 0, 0, yyvstop+21, 5, 0, yyvstop+24, 0, 0, yyvstop+26, 26, 0, yyvstop+29, 3, 0, yyvstop+32, 5, 0, yyvstop+34, 205, 0, yyvstop+36, 280, 0, yyvstop+39, 54, yysvec+17, yyvstop+42, 57, yysvec+17, yyvstop+45, 0, yysvec+6, yyvstop+48, 0, yysvec+7, 0, 0, 0, yyvstop+50, 0, yysvec+8, 0, 0, 0, yyvstop+52, 0, yysvec+9, 0, 0, 0, yyvstop+54, 0, 0, yyvstop+56, 0, 0, yyvstop+58, 0, yysvec+13, yyvstop+60, 0, 0, yyvstop+62, 0, yysvec+15, 0, 0, 0, yyvstop+64, 0, yysvec+16, yyvstop+66, 63, yysvec+17, yyvstop+68, 355, yysvec+17, yyvstop+70, 69, yysvec+17, yyvstop+72, 70, yysvec+17, yyvstop+74, 76, yysvec+17, yyvstop+76, 430, 0, yyvstop+78, 79, yysvec+17, yyvstop+80, 82, yysvec+17, yyvstop+82, 92, yysvec+17, yyvstop+84, 103, yysvec+17, yyvstop+86, 95, yysvec+17, yyvstop+88, 101, yysvec+17, yyvstop+90, 107, yysvec+17, yyvstop+92, 123, yysvec+17, yyvstop+94, 124, yysvec+17, yyvstop+96, 125, yysvec+17, yyvstop+98, 126, yysvec+17, yyvstop+100, 127, yysvec+17, yyvstop+102, 135, yysvec+17, yyvstop+104, 137, yysvec+17, yyvstop+106, 455, yysvec+17, yyvstop+108, 165, yysvec+17, yyvstop+110, 139, yysvec+17, yyvstop+112, 166, yysvec+17, yyvstop+114, 481, yysvec+17, yyvstop+116, 198, yysvec+17, yyvstop+118, 482, yysvec+17, yyvstop+120, 0, 0, yyvstop+122, 483, yysvec+17, yyvstop+124, 0, 0, yyvstop+126, 0, 0, yyvstop+128, 0, 0, 0}; struct yywork *yytop = yycrank+586; struct yysvf *yybgin = yysvec+1; unsigned char yymatch[] = { 00 ,01 ,01 ,01 ,01 ,01 ,01 ,01 , 01 ,01 ,012 ,01 ,01 ,01 ,01 ,01 , 01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 , 01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 , 040 ,01 ,'"' ,01 ,01 ,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$ */ int yylineno =1; # define YYU(x) x # define NLSTATE yyprevious=YYNEWLINE /* char yytext[YYLMAX]; * ***** nls8 ***** */ unsigned char yytext[YYLMAX]; struct yysvf *yylstate [YYLMAX], **yylsp, **yyolsp; /* char yysbuf[YYLMAX]; * char *yysptr = yysbuf; * ***** nls8 ***** */ unsigned char yysbuf[YYLMAX]; unsigned char *yysptr = yysbuf; int *yyfnd; extern struct yysvf *yyestate; int yyprevious = YYNEWLINE; yylook(){ register struct yysvf *yystate, **lsp; register struct yywork *yyt; struct yysvf *yyz; int yych, yyfirst; struct yywork *yyr; # ifdef LEXDEBUG int debug; # endif /* char *yylastch; * ***** nls8 ***** */ unsigned char *yylastch; /* start off machines */ # ifdef LEXDEBUG debug = 0; # endif yyfirst=1; if (!yymorfg) yylastch = yytext; else { yymorfg=0; yylastch = yytext+yyleng; } for(;;){ lsp = yylstate; yyestate = yystate = yybgin; if (yyprevious==YYNEWLINE) yystate++; for (;;){ # ifdef LEXDEBUG if(debug)fprintf(yyout,"state %d\n",yystate-yysvec-1); # endif yyt = &yycrank[yystate->yystoff]; if(yyt == yycrank && !yyfirst){ /* may not be any transitions */ yyz = yystate->yyother; if(yyz == 0)break; if(yyz->yystoff == 0)break; } *yylastch++ = yych = input(); yyfirst=0; tryagain: # ifdef LEXDEBUG if(debug){ fprintf(yyout,"char "); allprint(yych); putchar('\n'); } # endif yyr = yyt; if ( (int)yyt > (int)yycrank){ yyt = yyr + yych; if (yyt <= yytop && yyt->verify+yysvec == yystate){ if(yyt->advance+yysvec == YYLERR) /* error transitions */ {unput(*--yylastch);break;} *lsp++ = yystate = yyt->advance+yysvec; goto contin; } } # ifdef YYOPTIM else if((int)yyt < (int)yycrank) { /* r < yycrank */ yyt = yyr = yycrank+(yycrank-yyt); # ifdef LEXDEBUG if(debug)fprintf(yyout,"compressed state\n"); # endif yyt = yyt + yych; if(yyt <= yytop && yyt->verify+yysvec == yystate){ if(yyt->advance+yysvec == YYLERR) /* error transitions */ {unput(*--yylastch);break;} *lsp++ = yystate = yyt->advance+yysvec; goto contin; } yyt = yyr + YYU(yymatch[yych]); # ifdef LEXDEBUG if(debug){ fprintf(yyout,"try fall back character "); allprint(YYU(yymatch[yych])); putchar('\n'); } # endif if(yyt <= yytop && yyt->verify+yysvec == yystate){ if(yyt->advance+yysvec == YYLERR) /* error transition */ {unput(*--yylastch);break;} *lsp++ = yystate = yyt->advance+yysvec; goto contin; } } if ((yystate = yystate->yyother) && (yyt = &yycrank[yystate->yystoff]) != yycrank){ # ifdef LEXDEBUG if(debug)fprintf(yyout,"fall back to state %d\n",yystate-yysvec-1); # endif goto tryagain; } # endif else {unput(*--yylastch);break;} contin: # ifdef LEXDEBUG if(debug){ fprintf(yyout,"state %d char ",yystate-yysvec-1); allprint(yych); putchar('\n'); } # endif ; } # ifdef LEXDEBUG if(debug){ fprintf(yyout,"stopped at %d with ",*(lsp-1)-yysvec-1); allprint(yych); putchar('\n'); } # endif while (lsp-- > yylstate){ *yylastch-- = 0; if (*lsp != 0 && (yyfnd= (*lsp)->yystops) && *yyfnd > 0){ yyolsp = lsp; if(yyextra[*yyfnd]){ /* must backup */ while(yyback((*lsp)->yystops,-*yyfnd) != 1 && lsp > yylstate){ lsp--; unput(*yylastch--); } } yyprevious = YYU(*yylastch); yylsp = lsp; yyleng = yylastch-yytext+1; yytext[yyleng] = 0; # ifdef LEXDEBUG if(debug){ fprintf(yyout,"\nmatch "); sprint(yytext); fprintf(yyout," action %d\n",*yyfnd); } # endif return(*yyfnd++); } unput(*yylastch); } if (yytext[0] == 0 /* && feof(yyin) */) { yysptr=yysbuf; return(0); } yyprevious = yytext[0] = input(); if (yyprevious>0) output(yyprevious); yylastch=yytext; # ifdef LEXDEBUG if(debug)putchar('\n'); # endif } } # ifdef __cplusplus yyback(int *p, int m) # else yyback(p, m) int *p; # endif { if (p==0) return(0); while (*p) { if (*p++ == m) return(1); } return(0); } /* the following are only used in the lex library */ yyinput(){ return(input()); } #ifdef __cplusplus void yyoutput(int c) #else yyoutput(c) int c; # endif { output(c); } #ifdef __cplusplus void yyunput(int c) #else yyunput(c) int c; #endif { unput(c); }