File indexing completed on 2024-05-12 15:26:59
0001 /*************************************************************************** 0002 File : parser.h 0003 Project : LabPlot 0004 Description : Parser for mathematical expressions 0005 -------------------------------------------------------------------- 0006 Copyright : (C) 2014-2020 Stefan Gerlach (stefan.gerlach@uni.kn) 0007 Copyright : (C) 2014 Alexander Semke (alexander.semke@web.de) 0008 0009 ***************************************************************************/ 0010 0011 /*************************************************************************** 0012 * * 0013 * This program is free software; you can redistribute it and/or modify * 0014 * it under the terms of the GNU General Public License as published by * 0015 * the Free Software Foundation; either version 2 of the License, or * 0016 * (at your option) any later version. * 0017 * * 0018 * This program is distributed in the hope that it will be useful, * 0019 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0021 * GNU General Public License for more details. * 0022 * * 0023 * You should have received a copy of the GNU General Public License * 0024 * along with this program; if not, write to the Free Software * 0025 * Foundation, Inc., 51 Franklin Street, Fifth Floor, * 0026 * Boston, MA 02110-1301 USA * 0027 * * 0028 ***************************************************************************/ 0029 0030 #ifndef PARSER_H 0031 #define PARSER_H 0032 0033 /* uncomment to enable parser specific debugging */ 0034 /* #define PDEBUG 1 */ 0035 0036 struct cons { 0037 const char* name; 0038 double value; 0039 }; 0040 0041 struct funs { 0042 const char* name; 0043 #ifdef _MSC_VER /* MSVC needs void argument */ 0044 double (*fnct)(void); 0045 #else 0046 double (*fnct)(); 0047 #endif 0048 int argc; 0049 }; 0050 0051 /* variables to pass to parser */ 0052 #define MAX_VARNAME_LENGTH 10 0053 typedef struct parser_var { 0054 char name[MAX_VARNAME_LENGTH]; 0055 double value; 0056 } parser_var; 0057 0058 /* Function types */ 0059 #ifdef _MSC_VER /* MSVC needs void argument */ 0060 typedef double (*func_t) (void); 0061 #else 0062 typedef double (*func_t) (); 0063 #endif 0064 typedef double (*func_t1) (double); 0065 typedef double (*func_t2) (double, double); 0066 typedef double (*func_t3) (double, double, double); 0067 typedef double (*func_t4) (double, double, double, double); 0068 0069 /* structure for list of symbols */ 0070 typedef struct symbol { 0071 char *name; /* name of symbol */ 0072 int type; /* type of symbol: either VAR or FNCT */ 0073 union { 0074 double var; /* value of a VAR */ 0075 func_t fnctptr; /* value of a FNCT */ 0076 } value; 0077 struct symbol *next; /* next symbol */ 0078 } symbol; 0079 0080 void init_table(void); /* initialize symbol table */ 0081 void delete_table(void); /* delete symbol table */ 0082 int parse_errors(void); 0083 symbol* assign_symbol(const char* symbol_name, double value); 0084 int remove_symbol(const char* symbol_name); 0085 double parse(const char *string, const char *locale); 0086 double parse_with_vars(const char[], const parser_var[], int nvars, const char* locale); 0087 0088 extern struct cons _constants[]; 0089 extern struct funs _functions[]; 0090 0091 0092 #endif /*PARSER_H*/