My Project
programmer's documentation
Loading...
Searching...
No Matches
mei_evaluate.h
Go to the documentation of this file.
1#ifndef __MEI_EVALUATE_H__
2#define __MEI_EVALUATE_H__
3
10/*
11 This file is part of Code_Saturne, a general-purpose CFD tool.
12
13 Copyright (C) 1998-2019 EDF S.A.
14
15 This program is free software; you can redistribute it and/or modify it under
16 the terms of the GNU General Public License as published by the Free Software
17 Foundation; either version 2 of the License, or (at your option) any later
18 version.
19
20 This program is distributed in the hope that it will be useful, but WITHOUT
21 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
23 details.
24
25 You should have received a copy of the GNU General Public License along with
26 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
27 Street, Fifth Floor, Boston, MA 02110-1301, USA.
28*/
29
30/*----------------------------------------------------------------------------*/
31
32/*----------------------------------------------------------------------------
33 * Local headers
34 *----------------------------------------------------------------------------*/
35
36#include "mei_hash_table.h"
37#include "mei_node.h"
38
39/*----------------------------------------------------------------------------*/
40
41#ifdef __cplusplus
42extern "C" {
43#endif /* __cplusplus */
44
45/*============================================================================
46 * Type definitions
47 *============================================================================*/
48
54 char *string;
55 int errors;
56 int *columns;
57 int *lines;
58 char **labels;
59 hash_table_t *symbol;
60 mei_node_t *node;
61};
62
67typedef struct _mei_tree_t mei_tree_t;
68
69/*============================================================================
70 * Public function prototypes
71 *============================================================================*/
72
73/*----------------------------------------------------------------------------
74 * Returns a new interpreter.
75 *
76 * The node member is empty, the string member contains the mathematical
77 * expression and the symbol table is initialize with the standard symbols.
78 *
79 * parameters:
80 * expr <-- string characters of the mathematical expression
81 *
82 * returns:
83 * pointer to new interpreter structure.
84 *----------------------------------------------------------------------------*/
85
86mei_tree_t *
87mei_tree_new(const char *expr);
88
89/*----------------------------------------------------------------------------
90 * Returns a new interpreter. The node member is empty,
91 * the string member contains the mathematical expression and
92 * the symbol table is initialize with a existing table, which is shared by
93 * multiple interpreter.
94 *
95 * parameters:
96 * expr <-- string characters of the mathematical expression
97 * symbol_table <-- shared table of symbols
98 *
99 * returns:
100 * pointer to new interpreter structure.
101 *----------------------------------------------------------------------------*/
102
103mei_tree_t *
104mei_tree_new_with_shared_symbols(const char *expr,
105 hash_table_t *symbol_table);
106
107/*----------------------------------------------------------------------------
108 * Returns a new table of symbols. The table contains standard mathematical
109 * symbols
110 *----------------------------------------------------------------------------*/
111
112hash_table_t *
114
115/*----------------------------------------------------------------------------
116 * Calls the yacc parser.
117 * Returns 0 if the parsing is ok, or the number of errors, if errors occurs
118 *
119 * parameters:
120 * ev <-- interpreter
121 *----------------------------------------------------------------------------*/
122
123int
124mei_tree_builder(mei_tree_t *ev);
125
126/*----------------------------------------------------------------------------
127 * Inserts a constant (label and value) in the table of symbols associated to
128 * an interpreter.
129 *
130 * parameters:
131 * ev <-- interpreter
132 * str <-- label of the constant
133 * value <-- value associated to the constant
134 *----------------------------------------------------------------------------*/
135
136void
137mei_tree_insert(mei_tree_t *ev,
138 const char *str,
139 const double value);
140
141/*----------------------------------------------------------------------------
142 * Inserts a constant (label and value) in a table of symbols.
143 *
144 * parameters:
145 * symbo_table <-- table of symbols
146 * str <-- label of the constant
147 * value <-- value associated to the constant
148 *----------------------------------------------------------------------------*/
149
150void
151mei_symbol_table_insert(hash_table_t *symbol_table,
152 const char *str,
153 const double value);
154
155/*----------------------------------------------------------------------------
156 * Checks if the symbol 'str' exists in the expression stored in 'ev'.
157 *
158 * parameters:
159 * ev <-- interpreter in which we want to know if str exists
160 * str <-- symbol to find
161 *
162 * returns:
163 * 0 if the symbol exists in the symbol table, 1 otherwise.
164 *----------------------------------------------------------------------------*/
165
166int
167mei_tree_find_symbol(mei_tree_t *ev,
168 const char *str);
169
170/*----------------------------------------------------------------------------
171 * Checks if the symbols in a list exist in the expression.
172 *
173 * parameters:
174 * ev <-- interpreter in which we want to know if str exists
175 * str <-- symbol to find
176 *
177 * returns:
178 * number of missing symbols
179 *----------------------------------------------------------------------------*/
180
181int
182mei_tree_find_symbols(mei_tree_t *ev,
183 const int size,
184 const char **symbol);
185
186/*----------------------------------------------------------------------------
187 * Returns a value of a symbol (variable or constant) from an interpreter
188 * symbol table.
189 *
190 * parameters:
191 * ev <-- interpreter
192 * str <-- name of the symbol
193 *----------------------------------------------------------------------------*/
194
195double
196mei_tree_lookup(mei_tree_t *ev,
197 const char *str);
198
199/*----------------------------------------------------------------------------
200 * Evaluates the expression :
201 * 1) computes all values for variables inside the expression
202 * 2) returns a value from the intrepreted expression.
203 *
204 * parameters:
205 * ev <-- interpreter
206 *----------------------------------------------------------------------------*/
207
208double
209mei_evaluate(mei_tree_t *ev);
210
211/*----------------------------------------------------------------------------
212 * Free memory and return NULL.
213 *
214 * parameters:
215 * ev <-- interpreter
216 *----------------------------------------------------------------------------*/
217
218void
219mei_tree_destroy(mei_tree_t *ev);
220
221/*----------------------------------------------------------------------------*/
222
223#ifdef __cplusplus
224}
225#endif /* __cplusplus */
226
227#endif /* __MEI_EVALUATE_H__ */
228
double mei_evaluate(mei_tree_t *ev)
Evaluates the expression ev : 1) computes all values for variables inside the expression 2) returns a...
Definition mei_evaluate.c:857
hash_table_t * mei_table_symbols_new(void)
Returns a new table of symbols. The table contains standard mathematical symbols.
Definition mei_evaluate.c:582
mei_tree_t * mei_tree_new(const char *expr)
Returns a new interpreter. The node member is empty, the string member contains the mathematical expr...
Definition mei_evaluate.c:489
int mei_tree_builder(mei_tree_t *ev)
Call the yacc parser. Return 0 if the parsing is ok, or the number of errors, if errors occurs.
Definition mei_evaluate.c:606
void mei_symbol_table_insert(hash_table_t *symbol_table, const char *str, const double value)
Inserts a constant (label and value) in a table of symbols.
Definition mei_evaluate.c:728
mei_tree_t * mei_tree_new_with_shared_symbols(const char *expr, hash_table_t *symbol_table)
Returns a new interpreter. The node member is empty, the string member contains the mathematical expr...
Definition mei_evaluate.c:536
void mei_tree_destroy(mei_tree_t *ev)
Free memory and return NULL.
Definition mei_evaluate.c:872
void mei_tree_insert(mei_tree_t *ev, const char *str, const double value)
Inserts a constant (label and value) in the table of symbols associated to an interpreter.
Definition mei_evaluate.c:702
int mei_tree_find_symbol(mei_tree_t *ev, const char *str)
Check if the symbol str exists in the expression stored in ev.
Definition mei_evaluate.c:755
int mei_tree_find_symbols(mei_tree_t *ev, const int size, const char **symbol)
Check if the symbol str from a list exists in the expression. The list of missing symbols is stored i...
Definition mei_evaluate.c:789
double mei_tree_lookup(mei_tree_t *ev, const char *str)
Returns a value of the str symbol (variable or constant) from table of symbols of ev interpreter.
Definition mei_evaluate.c:827
Hash table, intended to provide a symbol table.
Nodal structure of the interpreter.
Structure defining an interpreter for a mathematical expression.
Definition mei_evaluate.h:53
mei_node_t * node
Definition mei_evaluate.h:60
int errors
Definition mei_evaluate.h:55
int * columns
Definition mei_evaluate.h:56
hash_table_t * symbol
Definition mei_evaluate.h:59
int * lines
Definition mei_evaluate.h:57
char ** labels
Definition mei_evaluate.h:58
char * string
Definition mei_evaluate.h:54