home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume8 / gnuplot1.10A / part01 / eval.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-09  |  3.0 KB  |  132 lines

  1. /*
  2.  *
  3.  *    G N U P L O T  --  eval.c
  4.  *
  5.  *  Copyright (C) 1986, 1987  Colin Kelley, Thomas Williams
  6.  *
  7.  *  You may use this code as you wish if credit is given and this message
  8.  *  is retained.
  9.  *
  10.  *  Please e-mail any useful additions to vu-vlsi!plot so they may be
  11.  *  included in later releases.
  12.  *
  13.  *  This file should be edited with 4-column tabs!  (:set ts=4 sw=4 in vi)
  14.  */
  15.  
  16. #include <stdio.h>
  17. #include "plot.h"
  18.  
  19. char *malloc();
  20.  
  21. extern int c_token;
  22. extern struct ft_entry ft[];
  23. extern struct udvt_entry *first_udv;
  24. extern struct udft_entry *first_udf;
  25. extern struct at_type at;
  26. extern struct lexical_unit token[];
  27.  
  28. struct value *integer();
  29.  
  30.  
  31.  
  32. struct udvt_entry *
  33. add_udv(t_num)  /* find or add value and return pointer */
  34. int t_num;
  35. {
  36. register struct udvt_entry **udv_ptr = &first_udv;
  37.  
  38.     /* check if it's already in the table... */
  39.  
  40.     while (*udv_ptr) {
  41.         if (equals(t_num,(*udv_ptr)->udv_name))
  42.             return(*udv_ptr);
  43.         udv_ptr = &((*udv_ptr)->next_udv);
  44.     }
  45.  
  46.     if (!(*udv_ptr = (struct udvt_entry *)
  47.         malloc((unsigned int)sizeof(struct udvt_entry))))
  48.             int_error("not enought memory for value",t_num);
  49.     (*udv_ptr)->next_udv = NULL;
  50.     copy_str((*udv_ptr)->udv_name,t_num);
  51.     (*udv_ptr)->udv_value.type = INT;    /* not necessary, but safe! */
  52.     (*udv_ptr)->udv_undef = TRUE;
  53.     return(*udv_ptr);
  54. }
  55.  
  56.  
  57. struct udft_entry *
  58. add_udf(t_num)  /* find or add function and return pointer */
  59. int t_num; /* index to token[] */
  60. {
  61. register struct udft_entry **udf_ptr = &first_udf;
  62.  
  63.     while (*udf_ptr) {
  64.         if (equals(t_num,(*udf_ptr)->udf_name))
  65.             return(*udf_ptr);
  66.         udf_ptr = &((*udf_ptr)->next_udf);
  67.     }
  68.     if (!(*udf_ptr = (struct udft_entry *)
  69.         malloc((unsigned int)sizeof(struct udft_entry))))
  70.             int_error("not enought memory for function",t_num);
  71.     (*udf_ptr)->next_udf = (struct udft_entry *) NULL;
  72.     (*udf_ptr)->definition = NULL;
  73.     (*udf_ptr)->at = NULL;
  74.     copy_str((*udf_ptr)->udf_name,t_num);
  75.     (void) integer(&((*udf_ptr)->dummy_value), 0);
  76.     return(*udf_ptr);
  77. }
  78.  
  79.  
  80. union argument *
  81. add_action(sf_index)
  82. enum operators sf_index;        /* index of p-code function */
  83. {
  84.     if (at.a_count >= MAX_AT_LEN)
  85.         int_error("action table overflow",NO_CARET);
  86.     at.actions[at.a_count].index = sf_index;
  87.     return(&(at.actions[at.a_count++].arg));
  88. }
  89.  
  90.  
  91. int standard(t_num)  /* return standard function index or 0 */
  92. {
  93. register int i;
  94.     for (i = (int)SF_START; ft[i].f_name != NULL; i++) {
  95.         if (equals(t_num,ft[i].f_name))
  96.             return(i);
  97.     }
  98.     return(0);
  99. }
  100.  
  101.  
  102.  
  103. execute_at(at_ptr)
  104. struct at_type *at_ptr;
  105. {
  106. register int i,index,count,offset;
  107.  
  108.     count = at_ptr->a_count;
  109.     for (i = 0; i < count;) {
  110.         index = (int)at_ptr->actions[i].index;
  111.         offset = (*ft[index].func)(&(at_ptr->actions[i].arg));
  112.         if (is_jump(index))
  113.             i += offset;
  114.         else
  115.             i++;
  116.     }
  117. }
  118.  
  119. /*
  120.  
  121.  'ft' is a table containing C functions within this program. 
  122.  
  123.  An 'action_table' contains pointers to these functions and arguments to be
  124.  passed to them. 
  125.  
  126.  at_ptr is a pointer to the action table which must be executed (evaluated)
  127.  
  128.  so the iterated line exectues the function indexed by the at_ptr and 
  129.  passes the address of the argument which is pointed to by the arg_ptr 
  130.  
  131. */
  132.