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

Diff of /stack/stack.c

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

revision 1.31 by teddy, Tue Feb 5 22:25:04 2002 UTC revision 1.34 by masse, Tue Feb 5 23:26:46 2002 UTC
# Line 58  typedef struct stackitem_struct Line 58  typedef struct stackitem_struct
58  typedef struct {  typedef struct {
59    stackitem *head;              /* Head of the stack */    stackitem *head;              /* Head of the stack */
60    hashtbl symbols;              /* Hash table of all variable bindings */    hashtbl symbols;              /* Hash table of all variable bindings */
61      int err;                      /* Error flag */
62  } environment;  } environment;
63    
64  /* A type for pointers to external functions */  /* A type for pointers to external functions */
# Line 348  stackitem* copy(stackitem* in_item) Line 349  stackitem* copy(stackitem* in_item)
349    return out_item;    return out_item;
350  }  }
351    
352    /* Recall a value from a symbol, if bound */
353  extern void rcl(environment *env)  extern void rcl(environment *env)
354  {  {
355    value *val;    value *val;
# Line 362  extern void rcl(environment *env) Line 364  extern void rcl(environment *env)
364      return;      return;
365    }    }
366    val=((symbol *)(env->head->item->content.ptr))->val;    val=((symbol *)(env->head->item->content.ptr))->val;
367      if(val == NULL){
368        printerr("Unbound variable");
369        return;
370      }
371    toss(env);            /* toss the symbol */    toss(env);            /* toss the symbol */
372    push_val(&(env->head), val); /* Return its bound value */    push_val(&(env->head), val); /* Return its bound value */
373  }  }
# Line 483  int stack_read(environment *env, char *i Line 489  int stack_read(environment *env, char *i
489        break;        break;
490      }      }
491      /* If symbol */      /* If symbol */
492      if((convert= sscanf(in_line, "%[^][ ;\n\r_]%[^\n\r]", temp, rest))) {      if((convert= sscanf(in_line, "%[^][ ;\n\r]%[^\n\r]", temp, rest))) {
493          push_sym(env, temp);          push_sym(env, temp);
494          break;          break;
495      }      }
# Line 638  extern void clear(environment *env) Line 644  extern void clear(environment *env)
644      toss(env);      toss(env);
645  }  }
646    
647    /* List all defined words */
648    extern void words(environment *env)
649    {
650      symbol *temp;
651      int i;
652      
653      for(i= 0; i<HASHTBLSIZE; i++) {
654        temp= env->symbols[i];
655        while(temp!=NULL) {
656          printf("%s\n", temp->id);
657          temp= temp->next;
658        }
659      }
660    }
661    
662    /* Forgets a symbol (remove it from the hash table) */
663    extern void forget(environment *env)
664    {
665      char* sym_id;
666      stackitem *stack_head= env->head;
667      symbol **hash_entry, *temp;
668    
669      if(stack_head==NULL || stack_head->item->type!=symb) {
670        printerr("Stack empty or not a symbol");
671        return;
672      }
673    
674      sym_id= ((symbol*)(stack_head->item->content.ptr))->id;
675      toss(env);
676    
677      hash_entry= hash(env->symbols, sym_id);
678      temp= *hash_entry;
679      *hash_entry= (*hash_entry)->next;
680      
681      if(temp->val!=NULL) {
682        free_val(temp->val);
683      }
684      free(temp->id);
685      free(temp);
686    }
687    
688  int main()  int main()
689  {  {
690    environment myenv;    environment myenv;

Legend:
Removed from v.1.31  
changed lines
  Added in v.1.34

root@recompile.se
ViewVC Help
Powered by ViewVC 1.1.26