My Project
programmer's documentation
Data Structures | Functions
mei_evaluate.h File Reference

Build an interpreter for a mathematical expression. More...

#include "mei_hash_table.h"
#include "mei_node.h"
Include dependency graph for mei_evaluate.h:

Go to the source code of this file.

Data Structures

struct  mei_tree_t
 Structure defining an interpreter for a mathematical expression. More...
 

Functions

mei_tree_t * mei_tree_new (const char *expr)
 Returns a new interpreter. The node member is empty, the string member contains the mathematical expression and the symbol table is initialize with the standard symbols. More...
 
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 expression and the symbol table is initialize with a existing table, which is shared by multiple interpreter. More...
 
hash_table_t * mei_table_symbols_new (void)
 Returns a new table of symbols. The table contains standard mathematical symbols. More...
 
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. More...
 
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. More...
 
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. More...
 
int mei_tree_find_symbol (mei_tree_t *ev, const char *str)
 Check if the symbol str exists in the expression stored in ev. More...
 
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 in ev->labels. More...
 
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. More...
 
double mei_evaluate (mei_tree_t *ev)
 Evaluates the expression ev : 1) computes all values for variables inside the expression 2) returns a value from the intrepreted expression. More...
 
void mei_tree_destroy (mei_tree_t *ev)
 Free memory and return NULL. More...
 

Detailed Description

Build an interpreter for a mathematical expression.

Function Documentation

◆ mei_evaluate()

double mei_evaluate ( mei_tree_t *  ev)

Evaluates the expression ev : 1) computes all values for variables inside the expression 2) returns a value from the intrepreted expression.

Parameters
[in]evinterpreter
Returns
value from the intrepreted expression

◆ mei_symbol_table_insert()

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.

Parameters
[in]symbol_tabletable of symbols
[in]strlabel of the constant
[in]valuevalue associated to the constant

◆ mei_table_symbols_new()

hash_table_t* mei_table_symbols_new ( void  )

Returns a new table of symbols. The table contains standard mathematical symbols.

Returns
table of symbols

◆ mei_tree_builder()

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.

Parameters
[in]evinterpreter
Returns
number of parsing errors

◆ mei_tree_destroy()

void mei_tree_destroy ( mei_tree_t *  ev)

Free memory and return NULL.

Parameters
[in]evinterpreter

◆ mei_tree_find_symbol()

int mei_tree_find_symbol ( mei_tree_t *  ev,
const char *  str 
)

Check if the symbol str exists in the expression stored in ev.

Parameters
[in]evinterpreter in which we want to know if str exists
[in]strsymbol to find
Returns
0 if the symbol exists in the symbol table, 1 if not

◆ mei_tree_find_symbols()

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 in ev->labels.

Parameters
[in]evinterpreter
[in]sizenumber of symbols to check
[in]symbollist of symbols
Returns
0 if all symbols exist, otherwise return the number of errors

◆ mei_tree_insert()

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.

Parameters
[in]evinterpreter
[in]strlabel of the constant
[in]valuevalue associated to the constant

◆ mei_tree_lookup()

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.

Parameters
[in]evinterpreter
[in]strname of the symbol
Returns
value of a symbol

◆ mei_tree_new()

mei_tree_t* mei_tree_new ( const char *  expr)

Returns a new interpreter. The node member is empty, the string member contains the mathematical expression and the symbol table is initialize with the standard symbols.

Parameters
[in]exprstring characters of the mathematical expression
Returns
new empty interpreter

◆ mei_tree_new_with_shared_symbols()

mei_tree_t* mei_tree_new_with_shared_symbols ( const char *const  expr,
hash_table_t *const  symbol_table 
)

Returns a new interpreter. The node member is empty, the string member contains the mathematical expression and the symbol table is initialize with a existing table, which is shared by multiple interpreter.

Parameters
[in]exprstring characters of the mathematical expression
[in]symbol_tableshared table of symbols
Returns
new empty interpreter