/* ** ** ETABLE.C Manipulates a table of tokens. ** ** Originally written 6/89 in ANSI C ** ** Eval is a floating point expression evaluator. ** This file last updated in version 1.10 ** For the version number, see eval.h ** Copyright (C) 1993 Will Menninger ** ** This program is free software; you can redistribute it and/or modify it ** under the terms of the GNU General Public License as published by the ** Free Software Foundation; either version 2 of the License, or any ** later version. ** ** This program is distributed in the hope that it will be useful, but ** WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ** General Public License for more details. ** ** You should have received a copy of the GNU General Public License along ** with this program; if not, write to the Free Software Foundation, Inc., ** 675 Mass Ave, Cambridge, MA 02139, USA. ** ** The author until 9/93 can be contacted at: ** e-mail: willus@ilm.pfc.mit.edu ** U.S. mail: Will Menninger, 45 River St., #2, Boston, MA 02108-1124 ** ** */ #include "eval.h" static TOKEN ttable[MAXINPUT+1]; static int ttp; static BOOLEAN is_operator (int type); #ifdef DEBUG static void print_table (void); #endif void clear_table(void) { ttp=0; } BOOLEAN add_token(TOKENPTR t) { if (ttp>MAXINPUT) { printf("Out of expression table space.\n"); return(0); } tokcpy(&ttable[ttp],t); ttp++; return(1); } BOOLEAN table_value(double *ret_val) { int i,j,k,nargs,max; double args[MAXARGS]; max=ttp; while (ttp>1) { for (i=0;iMAXARGS) return(eerror("Maximum number of function arguments exceeded.")); for (j=i,k=nargs-1;k>=0;k--) { for (j--;j>=0 && ttable[j].type==VOID;j--); if (j<0) return(eerror("Expression table lacking in arguments.")); args[k]=ttable[j].value; ttable[j].type=VOID; ttp--; } if (!result((int)ttable[i].type,ttable[i].code,args,&ttable[i].value)) return(0); ttable[i].type=NUMBER; } if (ttp!=1) return(eerror("Expression table unexpectedly empty.")); for (i=0;i