#ifdef __cplusplus #include extern "C" { extern void yyerror(char *); extern int yylex(); } #endif /* __cplusplus */ # line 2 "parser.yacc" # include # include "parser.h" parser_clause_list *clauses; parser_clause *interactive_clause; parser_term_list *last; int term_counter = 0; int func_ref_num = 0; char agent[50]; char dec_type; char action_type(); #define BLOCK_SIZE 100 functor **sym_table; int max_sym_size = 0; module_ptr parser_main(char *file_name); struct clause *parse_interactive_input(char *input); void yyerror(char *s); void print_table(); static void free_parser_mem(parser_clause_list *clauses); static void free_parser_clause(parser_clause *ptr); static void free_parser_term(parser_term *ptr); struct clause *convert_clause(parser_clause * cl); void InitilizeSymTable(); void update_type(int functor); int priority_count=0; static int error_flag = 0; # line 38 "parser.yacc" typedef union { int ival; char *sval; parser_term *tval; parser_term_list *tlval; parser_clause *cval; parser_clause_list **clval; } YYSTYPE; # define P_MODULE 257 # define P_ABDUCIBLE 258 # define P_RECURSIVE 259 # define P_VARIABLE 260 # define P_ATOM 261 # define P_PERIOD 262 # define P_COMMA 263 # define P_NUMBER 264 # define P_SYM_LIST 265 # define P_STRING 266 # define P_FORWARD 267 # define P_D_FORWARD 268 # define P_BACKWARD 269 # define P_DIRECT 270 #define yyclearin yychar = -1 #define yyerrok yyerrflag = 0 extern int yychar; #ifndef YYMAXDEPTH #define YYMAXDEPTH 150 #endif /* __YYSCLASS defines the scoping/storage class for global objects * that are NOT renamed by the -p option. By default these names * are going to be 'static' so that multi-definition errors * will not occur with multiple parsers. * If you want (unsupported) access to internal names you need * to define this to be null so it implies 'extern' scope. * This should not be used in conjunction with -p. */ #ifndef __YYSCLASS # define __YYSCLASS static #endif YYSTYPE yylval; __YYSCLASS YYSTYPE yyval; typedef int yytabelem; # define YYERRCODE 256 # line 363 "parser.yacc" # include "lex.yy.c" /********************************************************/ /* Interactive parser */ /********************************************************/ struct clause *parse_interactive_input(char *input) { FILE *fp; struct clause *cl; char buffer[100]; /* Initilize */ interactive_clause = NULL; if((fp = fopen("temp.term", "w")) == NULL) {printf("Can't create temp file\n" ); exit(1);} fprintf(fp,"%c%s%c\n", '{', input, '}'); fclose(fp); if((fp = fopen("temp.term", "r")) == NULL) {printf("Can't read term file\n" ); exit(1);} /* Direct the input of the lex */ yyin = fp; yyparse(); if(interactive_clause == NULL) { printf("Null clause\n"); cl = NULL; } else { cl = convert_clause(interactive_clause); } fclose(fp); return(cl); } /********************************************************/ /* string_to_term /********************************************************/ struct term *string_to_term(char *input) { FILE *fp; struct clause *cl; /* Initilize */ interactive_clause = NULL; if((fp = fopen("temp.term", "w")) == NULL) {printf("Can't create temp file\n" ); exit(1);} fprintf(fp,"%c%s%c%c\n", '{', input,'.', '}'); fclose(fp); if((fp = fopen("temp.term", "r")) == NULL) {printf("Can't read term file\n" ); exit(1);} /* Direct the input of the lex */ yyin = fp; yyparse(); if(interactive_clause == NULL) { printf("Null clause\n"); cl = NULL; } else { cl = convert_clause(interactive_clause); } fclose(fp); if (cl==NULL) return NULL; else return(cl->head); } /********************************************************/ /* PARSER_MAIN */ /********************************************************/ module_ptr read_module(char *file_name) { module_ptr module = NULL; FILE *fp = fopen(file_name, "r"); /* Initilize */ clauses = NULL; func_ref_num = 0; if (fp == NULL) {printf("Can't find file %s\n",file_name ); return(NULL);} /* Direct the input of the lex */ yyin = fp; /* Create a symbol table. */ if(max_sym_size == 0){ InitilizeSymTable(); } error_flag = 0; yyparse(); if(error_flag) { printf("Error in loading agent program\n"); } else { module = convert_structure(clauses, agent,term_counter,sym_table); } /* Free clauses memory */ if(clauses != NULL) free_parser_mem(clauses); fclose(fp); return(module); } void InitilizeSymTable() { /* read in the automatically generated reserved_word list */ #include "reserved_str.aux" int n=sizeof(reserved_names)/sizeof(char *); int i; int incomplete_table[]={KNOW}; int incomplete_number=sizeof(incomplete_table)/sizeof(int); sym_table = (functor **)my_alloc(BLOCK_SIZE*sizeof(functor *)); max_sym_size += BLOCK_SIZE; for(i=0;itype = 'S'; } for(i=0;itype='I'; } } /********************************************************/ /* FREE MEMORY */ /********************************************************/ static void free_parser_mem(parser_clause_list *clauses) { parser_clause_list *temp; while(clauses != NULL){ free_parser_clause(clauses->ptr); temp = clauses; clauses = clauses->next; free(temp); } } /********************************************************/ /* FREE CLAUSE */ /********************************************************/ static void free_parser_clause(parser_clause *ptr) { parser_term_list *temp = NULL; parser_term_list *args = ptr->body; free_parser_term(ptr->head); while(args != NULL){ free_parser_term(args->ptr); temp = args; args = args->next; free(temp); } } /********************************************************/ /* FREE TERM */ /********************************************************/ static void free_parser_term(parser_term *ptr) { parser_term_list *temp, *args = ptr->arguments; if (ptr->type == STRING) free(ptr->const_string); while(args != NULL){ free_parser_term(args->ptr); temp = args; args = args->next; free(temp); } free(ptr); } /********************************************************/ /* PARSER ERROR */ /********************************************************/ void yyerror(char *s) { printf("\n\nError %s\n", s); error_flag = 1; } /********************************************************/ /* PRINTING RUTINES */ /********************************************************/ void print_table() { int i; /* Print the table */ printf("\n/* \nThe term lookup table \n"); printf("%-5s%-40s%-5s\n", "Num", "Name", "Type", "Priority"); for(i=0; iname,sym_table[i]->type,sym_table[i]->priority); printf("*/\n"); } void print_module(module_ptr module) { int i; printf("\n\nModule name: %s\n", module->name); for(i=0; i< module->clause_counter; i++) print_clause(module->clause_array[i], sym_table); } void print_clause(clause_ptr ptr, functor **sym_table) { int i; print_term(ptr->head,sym_table); if (ptr->body_size!=0) { printf(" :-\n\t"); for(i=0; ibody_size; i++){ print_term(ptr->body[i],sym_table); if(i < ptr->body_size-1) printf(", \n\t"); } } printf(".\n"); } void pt(term_ptr t) { print_term(t,sym_table); printf("\n"); } void print_term(term_ptr ptr, functor **sym_table) { int i; if (ptr==NULL) { printf("Null term\n"); return; } switch(ptr->term_type){ case VARIABLE: printf("v%d", ptr->functor); break; case NONVAR: switch (ptr->functor) { case EMPTY_LIST: printf("[]"); break; case CONS_LIST: print_list(ptr,sym_table); break; default: printf("%s", sym_table[ptr->functor]->name); if(ptr->arity != 0) printf("("); for(i=0; iarity; i++){ print_term(ptr->argument_array[i],sym_table); if(i == ptr->arity-1) printf(")"); else printf(", "); } break; } break; case INTEGER: printf("$%d", ptr->functor); break; case TUPLE: printf("<"); for(i=0; iarity; i++){ print_term(ptr->argument_array[i],sym_table); if(i == ptr->arity-1) printf(">"); else printf(", "); } break; case STRING: printf("\"%s\"", ptr->const_string); break; } } /* ============================================================ | print_list() | |----------------------------------------------------------| | Params : 1)a term representing a list | | 2) symbol_table | | | | Desc : prints the list in Prolog way. . | | | | Returns: Nothing | |==========================================================| */ void print_list(struct term *l, functor **sym_table) { printf("["); while (l->functor==CONS_LIST) { print_term(l->argument_array[0],sym_table); if (t_next(l)->functor==CONS_LIST) printf(","); l=t_next(l); } if (t_empty_list(l)) printf("]"); else { printf("|"); print_term(l,sym_table); printf("]"); } } void update_type(int functor) { sym_table[functor]->type = dec_type; if (dec_type=='A') { sym_table[functor]->priority=priority_count++; } } __YYSCLASS yytabelem yyexca[] ={ -1, 1, 0, -1, -2, 0, }; # define YYNPROD 38 # define YYLAST 225 __YYSCLASS yytabelem yyact[]={ 11, 24, 59, 27, 52, 22, 23, 11, 47, 29, 25, 26, 58, 24, 11, 57, 24, 67, 70, 63, 56, 55, 65, 37, 19, 20, 3, 21, 66, 49, 54, 12, 64, 32, 8, 68, 35, 53, 12, 39, 28, 15, 30, 7, 18, 12, 31, 36, 6, 17, 5, 2, 16, 50, 34, 33, 1, 40, 41, 42, 44, 44, 0, 31, 0, 38, 0, 0, 0, 43, 45, 46, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 60, 0, 0, 36, 62, 61, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 69, 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, 51, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 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, 14, 9, 0, 0, 13, 0, 10, 14, 9, 48, 0, 13, 0, 10, 14, 9, 0, 0, 13, 0, 10, 0, 0, 0, 48 }; __YYSCLASS yytabelem yypact[]={ -97, -3000, -3000, -46, 1, -234, -98, -262, -259, 0, -3000, -53, -60, -3000, -3000, -238, -46, -3000, -1, -3000, -3000, -3000, -46, -46, -46, -46, -46, -3000, -46, -3000, -54, -3000, -3000, -64, -120, -3000, -3000, -4, -3000, -61, -241, -242, -3000, -247, -3000, -250, -39, -3000, -46, -3000, -3000, -46, -46, -243, -239, -3000, -3000, -3000, -3000, -3000, -3000, -3000, -3000, -3000, -65, -246, -6, -239, -244, -3000, -3000 }; __YYSCLASS yytabelem yypgo[]={ 0, 56, 34, 55, 36, 54, 53, 43, 42, 48, 52, 51, 50, 49, 44, 32 }; __YYSCLASS yytabelem yyr1[]={ 0, 1, 1, 11, 12, 12, 13, 14, 14, 15, 15, 15, 10, 10, 9, 9, 9, 9, 9, 7, 7, 2, 2, 2, 2, 2, 2, 2, 2, 2, 8, 8, 4, 3, 5, 5, 6, 6 }; __YYSCLASS yytabelem yyr2[]={ 0, 6, 7, 11, 0, 4, 14, 3, 3, 0, 3, 7, 1, 5, 9, 9, 9, 9, 5, 3, 7, 9, 3, 3, 5, 7, 5, 7, 3, 3, 3, 7, 3, 5, 3, 7, 1, 5 }; __YYSCLASS yytabelem yychk[]={ -3000, -1, -11, 123, 257, -12, -9, -7, -2, 261, 266, 60, 91, 264, 260, 40, -10, -13, -14, 258, 259, 125, 267, 268, 263, 269, 270, 262, 40, 62, -8, -2, 93, -3, -5, -4, -2, 261, -9, 40, -2, -2, -2, -7, -2, -7, -8, 62, 263, 93, -6, 263, 124, 41, 91, 262, 262, 262, 262, 41, -2, -4, -2, 262, -15, 261, 93, 263, 41, -15, 262 }; __YYSCLASS yytabelem yydef[]={ 0, -2, 4, 0, 0, 12, 0, 0, 19, 22, 23, 0, 0, 28, 29, 0, 1, 5, 0, 7, 8, 2, 0, 0, 0, 0, 0, 18, 0, 24, 0, 30, 26, 0, 36, 34, 32, 0, 13, 0, 0, 0, 20, 0, 19, 0, 0, 25, 0, 27, 33, 0, 0, 0, 9, 14, 15, 16, 17, 21, 31, 35, 37, 3, 0, 10, 0, 9, 0, 11, 6 }; typedef struct { char *t_name; int t_val; } yytoktype; #ifndef YYDEBUG # define YYDEBUG 0 /* don't allow debugging */ #endif #if YYDEBUG __YYSCLASS yytoktype yytoks[] = { "P_MODULE", 257, "P_ABDUCIBLE", 258, "P_RECURSIVE", 259, "P_VARIABLE", 260, "P_ATOM", 261, "P_PERIOD", 262, "P_COMMA", 263, "P_NUMBER", 264, "P_SYM_LIST", 265, "P_STRING", 266, "P_FORWARD", 267, "P_D_FORWARD", 268, "P_BACKWARD", 269, "P_DIRECT", 270, "-unknown-", -1 /* ends search */ }; __YYSCLASS char * yyreds[] = { "-no such reduction-", "module : agent_name decs clauses", "module : '{' clause '}'", "agent_name : P_MODULE '(' P_ATOM ')' P_PERIOD", "decs : /* empty */", "decs : decs declaration", "declaration : dec_type '(' '[' dec_list ']' ')' P_PERIOD", "dec_type : P_ABDUCIBLE", "dec_type : P_RECURSIVE", "dec_list : /* empty */", "dec_list : P_ATOM", "dec_list : P_ATOM P_COMMA dec_list", "clauses : /* empty */", "clauses : clauses clause", "clause : predicate_list P_FORWARD term P_PERIOD", "clause : predicate_list P_D_FORWARD term P_PERIOD", "clause : term P_BACKWARD predicate_list P_PERIOD", "clause : term P_DIRECT predicate_list P_PERIOD", "clause : term P_PERIOD", "predicate_list : term", "predicate_list : predicate_list P_COMMA term", "term : P_ATOM '(' var_term_list ')'", "term : P_ATOM", "term : P_STRING", "term : '<' '>'", "term : '<' var_term_list '>'", "term : '[' ']'", "term : '[' list_elements ']'", "term : P_NUMBER", "term : P_VARIABLE", "var_term_list : term", "var_term_list : var_term_list P_COMMA term", "cons_term : term", "list_elements : cons_term_list rest_of_list", "cons_term_list : cons_term", "cons_term_list : cons_term_list P_COMMA cons_term", "rest_of_list : /* empty */", "rest_of_list : '|' term", }; #endif /* YYDEBUG */ #define YYFLAG (-3000) /* @(#) $Revision: 66.3 $ */ /* ** Skeleton parser driver for yacc output */ #if defined(NLS) && !defined(NL_SETN) #include #endif #ifndef nl_msg #define nl_msg(i,s) (s) #endif /* ** yacc user known macros and defines */ #define YYERROR goto yyerrlab #ifndef __RUNTIME_YYMAXDEPTH #define YYACCEPT return(0) #define YYABORT return(1) #else #define YYACCEPT {free_stacks(); return(0);} #define YYABORT {free_stacks(); return(1);} #endif #define YYBACKUP( newtoken, newvalue )\ {\ if ( yychar >= 0 || ( yyr2[ yytmp ] >> 1 ) != 1 )\ {\ yyerror( (nl_msg(30001,"syntax error - cannot backup")) );\ goto yyerrlab;\ }\ yychar = newtoken;\ yystate = *yyps;\ yylval = newvalue;\ goto yynewstate;\ } #define YYRECOVERING() (!!yyerrflag) #ifndef YYDEBUG # define YYDEBUG 1 /* make debugging available */ #endif /* ** user known globals */ int yydebug; /* set to 1 to get debugging */ /* ** driver internal defines */ /* define for YYFLAG now generated by yacc program. */ /*#define YYFLAG (FLAGVAL)*/ /* ** global variables used by the parser */ # ifndef __RUNTIME_YYMAXDEPTH __YYSCLASS YYSTYPE yyv[ YYMAXDEPTH ]; /* value stack */ __YYSCLASS int yys[ YYMAXDEPTH ]; /* state stack */ # else __YYSCLASS YYSTYPE *yyv; /* pointer to malloc'ed value stack */ __YYSCLASS int *yys; /* pointer to malloc'ed stack stack */ #ifdef __cplusplus extern char *malloc(int); extern char *realloc(char *, int); extern void free(); # else extern char *malloc(); extern char *realloc(); extern void free(); # endif /* __cplusplus */ static int allocate_stacks(); static void free_stacks(); # ifndef YYINCREMENT # define YYINCREMENT (YYMAXDEPTH/2) + 10 # endif # endif /* __RUNTIME_YYMAXDEPTH */ long yymaxdepth = YYMAXDEPTH; __YYSCLASS YYSTYPE *yypv; /* top of value stack */ __YYSCLASS int *yyps; /* top of state stack */ __YYSCLASS int yystate; /* current state */ __YYSCLASS int yytmp; /* extra var (lasts between blocks) */ int yynerrs; /* number of errors */ __YYSCLASS int yyerrflag; /* error recovery flag */ int yychar; /* current input token number */ /* ** yyparse - return 0 if worked, 1 if syntax error not recovered from */ int yyparse() { register YYSTYPE *yypvt; /* top of value stack for $vars */ /* ** Initialize externals - yyparse may be called more than once */ # ifdef __RUNTIME_YYMAXDEPTH if (allocate_stacks()) YYABORT; # endif yypv = &yyv[-1]; yyps = &yys[-1]; yystate = 0; yytmp = 0; yynerrs = 0; yyerrflag = 0; yychar = -1; goto yystack; { register YYSTYPE *yy_pv; /* top of value stack */ register int *yy_ps; /* top of state stack */ register int yy_state; /* current state */ register int yy_n; /* internal state number info */ /* ** get globals into registers. ** branch to here only if YYBACKUP was called. */ yynewstate: yy_pv = yypv; yy_ps = yyps; yy_state = yystate; goto yy_newstate; /* ** get globals into registers. ** either we just started, or we just finished a reduction */ yystack: yy_pv = yypv; yy_ps = yyps; yy_state = yystate; /* ** top of for (;;) loop while no reductions done */ yy_stack: /* ** put a state and value onto the stacks */ #if YYDEBUG /* ** if debugging, look up token value in list of value vs. ** name pairs. 0 and negative (-1) are special values. ** Note: linear search is used since time is not a real ** consideration while debugging. */ if ( yydebug ) { register int yy_i; printf( "State %d, token ", yy_state ); if ( yychar == 0 ) printf( "end-of-file\n" ); else if ( yychar < 0 ) printf( "-none-\n" ); else { for ( yy_i = 0; yytoks[yy_i].t_val >= 0; yy_i++ ) { if ( yytoks[yy_i].t_val == yychar ) break; } printf( "%s\n", yytoks[yy_i].t_name ); } } #endif /* YYDEBUG */ if ( ++yy_ps >= &yys[ yymaxdepth ] ) /* room on stack? */ { # ifndef __RUNTIME_YYMAXDEPTH yyerror( (nl_msg(30002,"yacc stack overflow")) ); YYABORT; # else /* save old stack bases to recalculate pointers */ YYSTYPE * yyv_old = yyv; int * yys_old = yys; yymaxdepth += YYINCREMENT; yys = (int *) realloc(yys, yymaxdepth * sizeof(int)); yyv = (YYSTYPE *) realloc(yyv, yymaxdepth * sizeof(YYSTYPE)); if (yys==0 || yyv==0) { yyerror( (nl_msg(30002,"yacc stack overflow")) ); YYABORT; } /* Reset pointers into stack */ yy_ps = (yy_ps - yys_old) + yys; yyps = (yyps - yys_old) + yys; yy_pv = (yy_pv - yyv_old) + yyv; yypv = (yypv - yyv_old) + yyv; # endif } *yy_ps = yy_state; *++yy_pv = yyval; /* ** we have a new state - find out what to do */ yy_newstate: if ( ( yy_n = yypact[ yy_state ] ) <= YYFLAG ) goto yydefault; /* simple state */ #if YYDEBUG /* ** if debugging, need to mark whether new token grabbed */ yytmp = yychar < 0; #endif if ( ( yychar < 0 ) && ( ( yychar = yylex() ) < 0 ) ) yychar = 0; /* reached EOF */ #if YYDEBUG if ( yydebug && yytmp ) { register int yy_i; printf( "Received token " ); if ( yychar == 0 ) printf( "end-of-file\n" ); else if ( yychar < 0 ) printf( "-none-\n" ); else { for ( yy_i = 0; yytoks[yy_i].t_val >= 0; yy_i++ ) { if ( yytoks[yy_i].t_val == yychar ) break; } printf( "%s\n", yytoks[yy_i].t_name ); } } #endif /* YYDEBUG */ if ( ( ( yy_n += yychar ) < 0 ) || ( yy_n >= YYLAST ) ) goto yydefault; if ( yychk[ yy_n = yyact[ yy_n ] ] == yychar ) /*valid shift*/ { yychar = -1; yyval = yylval; yy_state = yy_n; if ( yyerrflag > 0 ) yyerrflag--; goto yy_stack; } yydefault: if ( ( yy_n = yydef[ yy_state ] ) == -2 ) { #if YYDEBUG yytmp = yychar < 0; #endif if ( ( yychar < 0 ) && ( ( yychar = yylex() ) < 0 ) ) yychar = 0; /* reached EOF */ #if YYDEBUG if ( yydebug && yytmp ) { register int yy_i; printf( "Received token " ); if ( yychar == 0 ) printf( "end-of-file\n" ); else if ( yychar < 0 ) printf( "-none-\n" ); else { for ( yy_i = 0; yytoks[yy_i].t_val >= 0; yy_i++ ) { if ( yytoks[yy_i].t_val == yychar ) { break; } } printf( "%s\n", yytoks[yy_i].t_name ); } } #endif /* YYDEBUG */ /* ** look through exception table */ { register int *yyxi = yyexca; while ( ( *yyxi != -1 ) || ( yyxi[1] != yy_state ) ) { yyxi += 2; } while ( ( *(yyxi += 2) >= 0 ) && ( *yyxi != yychar ) ) ; if ( ( yy_n = yyxi[1] ) < 0 ) YYACCEPT; } } /* ** check for syntax error */ if ( yy_n == 0 ) /* have an error */ { /* no worry about speed here! */ switch ( yyerrflag ) { case 0: /* new error */ yyerror( (nl_msg(30003,"syntax error")) ); yynerrs++; goto skip_init; yyerrlab: /* ** get globals into registers. ** we have a user generated syntax type error */ yy_pv = yypv; yy_ps = yyps; yy_state = yystate; yynerrs++; skip_init: case 1: case 2: /* incompletely recovered error */ /* try again... */ yyerrflag = 3; /* ** find state where "error" is a legal ** shift action */ while ( yy_ps >= yys ) { yy_n = yypact[ *yy_ps ] + YYERRCODE; if ( yy_n >= 0 && yy_n < YYLAST && yychk[yyact[yy_n]] == YYERRCODE) { /* ** simulate shift of "error" */ yy_state = yyact[ yy_n ]; goto yy_stack; } /* ** current state has no shift on ** "error", pop stack */ #if YYDEBUG # define _POP_ "Error recovery pops state %d, uncovers state %d\n" if ( yydebug ) printf( _POP_, *yy_ps, yy_ps[-1] ); # undef _POP_ #endif yy_ps--; yy_pv--; } /* ** there is no state on stack with "error" as ** a valid shift. give up. */ YYABORT; case 3: /* no shift yet; eat a token */ #if YYDEBUG /* ** if debugging, look up token in list of ** pairs. 0 and negative shouldn't occur, ** but since timing doesn't matter when ** debugging, it doesn't hurt to leave the ** tests here. */ if ( yydebug ) { register int yy_i; printf( "Error recovery discards " ); if ( yychar == 0 ) printf( "token end-of-file\n" ); else if ( yychar < 0 ) printf( "token -none-\n" ); else { for ( yy_i = 0; yytoks[yy_i].t_val >= 0; yy_i++ ) { if ( yytoks[yy_i].t_val == yychar ) { break; } } printf( "token %s\n", yytoks[yy_i].t_name ); } } #endif /* YYDEBUG */ if ( yychar == 0 ) /* reached EOF. quit */ YYABORT; yychar = -1; goto yy_newstate; } }/* end if ( yy_n == 0 ) */ /* ** reduction by production yy_n ** put stack tops, etc. so things right after switch */ #if YYDEBUG /* ** if debugging, print the string that is the user's ** specification of the reduction which is just about ** to be done. */ if ( yydebug ) printf( "Reduce by (%d) \"%s\"\n", yy_n, yyreds[ yy_n ] ); #endif yytmp = yy_n; /* value to switch over */ yypvt = yy_pv; /* $vars top of value stack */ /* ** Look in goto table for next state ** Sorry about using yy_state here as temporary ** register variable, but why not, if it works... ** If yyr2[ yy_n ] doesn't have the low order bit ** set, then there is no action to be done for ** this reduction. So, no saving & unsaving of ** registers done. The only difference between the ** code just after the if and the body of the if is ** the goto yy_stack in the body. This way the test ** can be made before the choice of what to do is needed. */ { /* length of production doubled with extra bit */ register int yy_len = yyr2[ yy_n ]; if ( !( yy_len & 01 ) ) { yy_len >>= 1; yyval = ( yy_pv -= yy_len )[1]; /* $$ = $1 */ yy_state = yypgo[ yy_n = yyr1[ yy_n ] ] + *( yy_ps -= yy_len ) + 1; if ( yy_state >= YYLAST || yychk[ yy_state = yyact[ yy_state ] ] != -yy_n ) { yy_state = yyact[ yypgo[ yy_n ] ]; } goto yy_stack; } yy_len >>= 1; yyval = ( yy_pv -= yy_len )[1]; /* $$ = $1 */ yy_state = yypgo[ yy_n = yyr1[ yy_n ] ] + *( yy_ps -= yy_len ) + 1; if ( yy_state >= YYLAST || yychk[ yy_state = yyact[ yy_state ] ] != -yy_n ) { yy_state = yyact[ yypgo[ yy_n ] ]; } } /* save until reenter driver code */ yystate = yy_state; yyps = yy_ps; yypv = yy_pv; } /* ** code supplied by user is placed in this switch */ switch( yytmp ) { case 2: # line 64 "parser.yacc" {interactive_clause = yypvt[-1].cval;} break; case 3: # line 68 "parser.yacc" {strcpy(agent, sym_table[yypvt[-2].ival]->name); } break; case 7: # line 79 "parser.yacc" {dec_type = 'A';} break; case 8: # line 80 "parser.yacc" {dec_type = 'R';} break; case 10: # line 84 "parser.yacc" {update_type(yypvt[-0].ival);} break; case 11: # line 85 "parser.yacc" {update_type(yypvt[-2].ival);} break; case 12: # line 89 "parser.yacc" { yyval.clval = &clauses; } break; case 13: # line 93 "parser.yacc" { *yypvt[-1].clval = (parser_clause_list *)my_alloc(sizeof(parser_clause_list)); (*yypvt[-1].clval)->next = NULL; (*yypvt[-1].clval)->ptr = yypvt[-0].cval; yyval.clval = &(*yypvt[-1].clval)->next; } break; case 14: # line 102 "parser.yacc" { parser_clause *pclause; pclause = (parser_clause *)my_alloc(sizeof(parser_clause)); pclause->head = yypvt[-1].tval; pclause->body = yypvt[-3].tlval; pclause->var_counter = yypvt[-0].ival; pclause->clause_type = FORWARD_CLAUSE; yyval.cval = pclause; } break; case 15: # line 112 "parser.yacc" { parser_clause *pclause; pclause = (parser_clause *)my_alloc(sizeof(parser_clause)); pclause->head = yypvt[-1].tval; pclause->body = yypvt[-3].tlval; pclause->var_counter = yypvt[-0].ival; pclause->clause_type = DIRECT_FORWARD_CLAUSE; yyval.cval = pclause; } break; case 16: # line 122 "parser.yacc" { parser_clause *pclause; pclause = (parser_clause *)my_alloc(sizeof(parser_clause)); pclause->head = yypvt[-3].tval; pclause->body = yypvt[-1].tlval; pclause->var_counter = yypvt[-0].ival; pclause->clause_type = BACKWARD_CLAUSE; yyval.cval = pclause; } break; case 17: # line 133 "parser.yacc" { parser_clause *pclause; pclause = (parser_clause *)my_alloc(sizeof(parser_clause)); pclause->head = yypvt[-3].tval; pclause->body = yypvt[-1].tlval; pclause->var_counter = yypvt[-0].ival; pclause->clause_type = DIRECT_CLAUSE; yyval.cval = pclause; } break; case 18: # line 144 "parser.yacc" { parser_clause *pclause; pclause = (parser_clause *)my_alloc(sizeof(parser_clause)); pclause->head = yypvt[-1].tval; pclause->body = NULL; pclause->var_counter = yypvt[-0].ival; pclause->clause_type = DIRECT_CLAUSE; yyval.cval = pclause; } break; case 19: # line 158 "parser.yacc" { parser_term_list *lterm; /* New predicate list */ lterm = (parser_term_list *)my_alloc(sizeof(parser_term_list)); lterm->next = NULL; lterm->ptr = yypvt[-0].tval; last = lterm; yyval.tlval = lterm; } break; case 20: # line 169 "parser.yacc" { last->next = (parser_term_list *)my_alloc(sizeof(parser_term_list)); last = last->next; last->next = NULL; last->ptr = yypvt[-0].tval; yyval.tlval = yypvt[-2].tlval; } break; case 21: # line 180 "parser.yacc" { parser_term * pterm; pterm = (parser_term *)my_alloc(sizeof(parser_term)); pterm->type = NONVAR; pterm->index = yypvt[-3].ival; pterm->const_string = NULL; pterm->arguments = yypvt[-1].tlval; yyval.tval = pterm; } break; case 22: # line 192 "parser.yacc" { parser_term * pterm; pterm = (parser_term *)my_alloc(sizeof(parser_term)); pterm->type = NONVAR; pterm->index = yypvt[-0].ival; pterm->const_string = NULL; pterm->arguments = NULL; yyval.tval = pterm; } break; case 23: # line 203 "parser.yacc" { parser_term * pterm; char *temp ; pterm = (parser_term *)my_alloc(sizeof(parser_term)); pterm->type = STRING; pterm->index = 0; /* Remove the quatation marks from the string */ temp = yypvt[-0].sval+1; temp[strlen(temp)-1] = '\0'; pterm->const_string = (char *)my_alloc(strlen(temp)+1); strcpy(pterm->const_string, temp); pterm->arguments = NULL; yyval.tval = pterm; } break; case 24: # line 219 "parser.yacc" { parser_term * pterm; pterm = (parser_term *)my_alloc(sizeof(parser_term)); pterm->type = TUPLE; pterm->index = 0; pterm->arguments = NULL; yyval.tval = pterm; } break; case 25: # line 229 "parser.yacc" { parser_term * pterm; pterm = (parser_term *)my_alloc(sizeof(parser_term)); pterm->type = TUPLE; pterm->index = 0; pterm->arguments = yypvt[-1].tlval; yyval.tval = pterm; } break; case 26: # line 239 "parser.yacc" { parser_term * pterm; pterm = (parser_term *)my_alloc(sizeof(parser_term)); pterm->type = NONVAR; pterm->index = EMPTY_LIST; pterm->arguments = NULL; yyval.tval = pterm; } break; case 27: # line 249 "parser.yacc" { yyval.tval = yypvt[-1].tval; } break; case 28: # line 253 "parser.yacc" { parser_term * pterm; pterm = (parser_term *)my_alloc(sizeof(parser_term)); pterm->type = INTEGER; pterm->index = yypvt[-0].ival; pterm->const_string = NULL; pterm->arguments = NULL; yyval.tval = pterm; } break; case 29: # line 264 "parser.yacc" { parser_term * pterm; pterm = (parser_term *)my_alloc(sizeof(parser_term)); pterm->type = VARIABLE; pterm->index = yypvt[-0].ival; pterm->const_string = NULL; pterm->arguments = NULL; yyval.tval = pterm; } break; case 30: # line 277 "parser.yacc" { parser_term_list * t2; /* New var_term list */ t2 = (parser_term_list *)my_alloc(sizeof(parser_term_list)); t2->next = NULL; t2->ptr = yypvt[-0].tval; yyval.tlval = t2; } break; case 31: # line 287 "parser.yacc" { parser_term_list *t1; t1 = yypvt[-2].tlval; while(t1->next != NULL) t1 = t1->next; t1->next = (parser_term_list *)my_alloc(sizeof(parser_term_list)); t1 = t1->next; t1->next = NULL; t1->ptr = yypvt[-0].tval; yyval.tlval = yypvt[-2].tlval; } break; case 32: # line 301 "parser.yacc" { parser_term * pterm; parser_term_list * t1; pterm = (parser_term *)my_alloc(sizeof(parser_term)); t1 = (parser_term_list *)my_alloc(sizeof(parser_term_list)); t1->next = NULL; t1->ptr = yypvt[-0].tval; pterm->type = NONVAR; pterm->index = CONS_LIST; pterm->arguments = t1; yyval.tval = pterm; } break; case 33: # line 317 "parser.yacc" { parser_term_list *t1 = (yypvt[-1].tval)->arguments; /* The last element in the list have only one argument. */ while(t1->next != NULL) t1 = t1->next->ptr->arguments; t1->next = (parser_term_list *)my_alloc(sizeof(parser_term_list)); t1 = t1->next; t1->next = NULL; t1->ptr = yypvt[-0].tval; yyval.tval = yypvt[-1].tval; } break; case 34: # line 331 "parser.yacc" { yyval.tval = yypvt[-0].tval; } break; case 35: # line 335 "parser.yacc" { parser_term_list *t1 = (yypvt[-2].tval)->arguments; /* The last element in the list have only one argument. */ while(t1->next != NULL) t1 = t1->next->ptr->arguments; t1->next = (parser_term_list *)my_alloc(sizeof(parser_term_list)); t1 = t1->next; t1->next = NULL; t1->ptr = yypvt[-0].tval; yyval.tval = yypvt[-2].tval; } break; case 36: # line 349 "parser.yacc" { parser_term * pterm; pterm = (parser_term *)my_alloc(sizeof(parser_term)); pterm->type = NONVAR; pterm->index = EMPTY_LIST; pterm->arguments = NULL; yyval.tval = pterm; } break; case 37: # line 359 "parser.yacc" { yyval.tval = yypvt[-0].tval; } break; } goto yystack; /* reset registers in driver code */ } # ifdef __RUNTIME_YYMAXDEPTH static int allocate_stacks() { /* allocate the yys and yyv stacks */ yys = (int *) malloc(yymaxdepth * sizeof(int)); yyv = (YYSTYPE *) malloc(yymaxdepth * sizeof(YYSTYPE)); if (yys==0 || yyv==0) { yyerror( (nl_msg(30004,"unable to allocate space for yacc stacks")) ); return(1); } else return(0); } static void free_stacks() { if (yys!=0) free((char *) yys); if (yyv!=0) free((char *) yyv); } # endif /* defined(__RUNTIME_YYMAXDEPTH) */