--- stack/stack.c 2002/02/11 01:20:35 1.70 +++ stack/stack.c 2002/02/11 22:07:47 1.71 @@ -480,8 +480,6 @@ push_val(&(env->head), val); /* Return its bound value */ } -void stack_read(environment*, char*); - /* If the top element is a symbol, determine if it's bound to a function value, and if it is, toss the symbol and execute the function. */ @@ -490,7 +488,6 @@ funcp in_func; value* temp_val; stackitem* iterator; - char* temp_string; if(env->head==NULL) { printerr("Too Few Arguments"); @@ -542,22 +539,7 @@ free_val(temp_val); return; - /* If it's a string */ - case string: - temp_val= env->head->item; - env->head->item->refcount++; - toss(env); - if(env->err) return; - temp_string= malloc(strlen((char*)temp_val->content.ptr)+5); - strcpy(temp_string, "[ "); - strcpy(temp_string+2, (char*)temp_val->content.ptr); - free_val(temp_val); - strcat(temp_string, " ]"); - stack_read(env, temp_string); - free(temp_string); - goto eval_start; - - case integer: + default: return; } } @@ -632,85 +614,6 @@ rev(env); } -/* Parse input. */ -void stack_read(environment *env, char *in_line) -{ - char *temp, *rest; - int itemp; - size_t inlength= strlen(in_line)+1; - int convert= 0; - - temp= malloc(inlength); - rest= malloc(inlength); - - do { - /* If comment */ - if((convert= sscanf(in_line, "#%[^\n\r]", rest))) { - free(temp); free(rest); - return; - } - - /* If string */ - if((convert= sscanf(in_line, "\"%[^\"\n\r]\" %[^\n\r]", temp, rest))) { - push_cstring(&(env->head), temp); - break; - } - /* If integer */ - if((convert= sscanf(in_line, "%d %[^\n\r]", &itemp, rest))) { - push_int(&(env->head), itemp); - break; - } - /* Escape ';' with '\' */ - if((convert= sscanf(in_line, "\\%c%[^\n\r]", temp, rest))) { - temp[1]= '\0'; - push_sym(env, temp); - break; - } - /* If symbol */ - if((convert= sscanf(in_line, "%[^][ ;\n\r]%[^\n\r]", temp, rest))) { - push_sym(env, temp); - break; - } - /* If single char */ - if((convert= sscanf(in_line, "%c%[^\n\r]", temp, rest))) { - if(*temp==';') { - if(!env->non_eval_flag) { - eval(env); /* Evaluate top element */ - break; - } - - push_sym(env, ";"); - break; - } - - if(*temp==']') { - push_sym(env, "["); - pack(env); - if(env->non_eval_flag) - env->non_eval_flag--; - break; - } - - if(*temp=='[') { - push_sym(env, "["); - env->non_eval_flag++; - break; - } - } - } while(0); - - free(temp); - - if(convert<2) { - free(rest); - return; - } - - stack_read(env, rest); - - free(rest); -} - /* Relocate elements of the list on the stack. */ extern void expand(environment *env) { @@ -908,12 +811,13 @@ while(1) { if(myenv.in_string==NULL) - printf("okidok\n "); + printstack(&myenv); read(&myenv); if(myenv.err) { printf("(error %d) ", myenv.err); myenv.err=0; - } else if(myenv.head->item->type==symb + } else if(myenv.head!=NULL + && myenv.head->item->type==symb && ((symbol*)(myenv.head->item->content.ptr))->id[0]==';') { toss(&myenv); /* No error check in main */ eval(&myenv); @@ -1284,15 +1188,15 @@ /* Read a value and place on stack */ extern void read(environment *env) { - const char symbform[]= "%[a-zA-Z0-9!$%*+./:<=>?@^_~-]%100c"; - const char strform[]= "\"%[^\"]\"%100c"; - const char intform[]= "%i%100c"; - const char blankform[]= "%*[ \t]%100c"; - const char ebrackform[]= "%*1[]]%100c"; - const char semicform[]= "%*1[;]%100c"; - const char bbrackform[]= "%*1[[]%100c"; + const char symbform[]= "%[a-zA-Z0-9!$%*+./:<=>?@^_~-]%[\001-\377]"; + const char strform[]= "\"%[^\"]\"%[\001-\377]"; + const char intform[]= "%i%[\001-\377]"; + const char blankform[]= "%*[ \t]%[\001-\377]"; + const char ebrackform[]= "%*1[]]%[\001-\377]"; + const char semicform[]= "%*1[;]%[\001-\377]"; + const char bbrackform[]= "%*1[[]%[\001-\377]"; - int itemp, rerun= 0; + int itemp; static int depth= 0; char *rest, *match; size_t inlength; @@ -1310,7 +1214,7 @@ rest= malloc(inlength); if(sscanf(env->in_string, blankform, rest)) { - rerun= 1; + ; } else if(sscanf(env->in_string, intform, &itemp, rest) > 0) { push_int(&(env->head), itemp); } else if(sscanf(env->in_string, strform, match, rest) > 0) { @@ -1336,6 +1240,6 @@ env->in_string= rest; - if(rerun || depth) + if(depth) return read(env); }