/[cvs]/stack/stack.c
ViewVC logotype

Diff of /stack/stack.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.70 by masse, Mon Feb 11 01:20:35 2002 UTC revision 1.71 by masse, Mon Feb 11 22:07:47 2002 UTC
# Line 480  extern void rcl(environment *env) Line 480  extern void rcl(environment *env)
480    push_val(&(env->head), val); /* Return its bound value */    push_val(&(env->head), val); /* Return its bound value */
481  }  }
482    
 void stack_read(environment*, char*);  
   
483  /* If the top element is a symbol, determine if it's bound to a  /* If the top element is a symbol, determine if it's bound to a
484     function value, and if it is, toss the symbol and execute the     function value, and if it is, toss the symbol and execute the
485     function. */     function. */
# Line 490  extern void eval(environment *env) Line 488  extern void eval(environment *env)
488    funcp in_func;    funcp in_func;
489    value* temp_val;    value* temp_val;
490    stackitem* iterator;    stackitem* iterator;
   char* temp_string;  
491    
492    if(env->head==NULL) {    if(env->head==NULL) {
493      printerr("Too Few Arguments");      printerr("Too Few Arguments");
# Line 542  extern void eval(environment *env) Line 539  extern void eval(environment *env)
539      free_val(temp_val);      free_val(temp_val);
540      return;      return;
541    
542      /* If it's a string */    default:
   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:  
543      return;      return;
544    }    }
545  }  }
# Line 632  extern void pack(environment *env) Line 614  extern void pack(environment *env)
614    rev(env);    rev(env);
615  }  }
616    
 /* 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);  
 }  
   
617  /* Relocate elements of the list on the stack. */  /* Relocate elements of the list on the stack. */
618  extern void expand(environment *env)  extern void expand(environment *env)
619  {  {
# Line 908  int main() Line 811  int main()
811    
812    while(1) {    while(1) {
813      if(myenv.in_string==NULL)      if(myenv.in_string==NULL)
814        printf("okidok\n ");        printstack(&myenv);
815      read(&myenv);      read(&myenv);
816      if(myenv.err) {      if(myenv.err) {
817        printf("(error %d) ", myenv.err);        printf("(error %d) ", myenv.err);
818        myenv.err=0;        myenv.err=0;
819      } else if(myenv.head->item->type==symb      } else if(myenv.head!=NULL
820                  && myenv.head->item->type==symb
821                && ((symbol*)(myenv.head->item->content.ptr))->id[0]==';') {                && ((symbol*)(myenv.head->item->content.ptr))->id[0]==';') {
822        toss(&myenv);             /* No error check in main */        toss(&myenv);             /* No error check in main */
823        eval(&myenv);        eval(&myenv);
# Line 1284  extern void readline(environment *env) { Line 1188  extern void readline(environment *env) {
1188    
1189  /* Read a value and place on stack */  /* Read a value and place on stack */
1190  extern void read(environment *env) {  extern void read(environment *env) {
1191    const char symbform[]= "%[a-zA-Z0-9!$%*+./:<=>?@^_~-]%100c";    const char symbform[]= "%[a-zA-Z0-9!$%*+./:<=>?@^_~-]%[\001-\377]";
1192    const char strform[]= "\"%[^\"]\"%100c";    const char strform[]= "\"%[^\"]\"%[\001-\377]";
1193    const char intform[]= "%i%100c";    const char intform[]= "%i%[\001-\377]";
1194    const char blankform[]= "%*[ \t]%100c";    const char blankform[]= "%*[ \t]%[\001-\377]";
1195    const char ebrackform[]= "%*1[]]%100c";    const char ebrackform[]= "%*1[]]%[\001-\377]";
1196    const char semicform[]= "%*1[;]%100c";    const char semicform[]= "%*1[;]%[\001-\377]";
1197    const char bbrackform[]= "%*1[[]%100c";    const char bbrackform[]= "%*1[[]%[\001-\377]";
1198    
1199    int itemp, rerun= 0;    int itemp;
1200    static int depth= 0;    static int depth= 0;
1201    char *rest, *match;    char *rest, *match;
1202    size_t inlength;    size_t inlength;
# Line 1310  extern void read(environment *env) { Line 1214  extern void read(environment *env) {
1214    rest= malloc(inlength);    rest= malloc(inlength);
1215    
1216    if(sscanf(env->in_string, blankform, rest)) {    if(sscanf(env->in_string, blankform, rest)) {
1217      rerun= 1;          ;
1218    } else if(sscanf(env->in_string, intform, &itemp, rest) > 0) {    } else if(sscanf(env->in_string, intform, &itemp, rest) > 0) {
1219      push_int(&(env->head), itemp);      push_int(&(env->head), itemp);
1220    } else if(sscanf(env->in_string, strform, match, rest) > 0) {    } else if(sscanf(env->in_string, strform, match, rest) > 0) {
# Line 1336  extern void read(environment *env) { Line 1240  extern void read(environment *env) {
1240    
1241    env->in_string= rest;    env->in_string= rest;
1242    
1243    if(rerun || depth)    if(depth)
1244      return read(env);      return read(env);
1245  }  }

Legend:
Removed from v.1.70  
changed lines
  Added in v.1.71

root@recompile.se
ViewVC Help
Powered by ViewVC 1.1.26