My Project
programmer's documentation
|
Build an interpreter for a mathematical expression. More...
#include "cs_defs.h"
#include <assert.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "bft_mem.h"
#include "bft_printf.h"
#include "bft_error.h"
#include "mei_node.h"
#include "mei_parser_glob.h"
#include "mei_parser.h"
#include "mei_evaluate.h"
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 *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. 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... | |
Build an interpreter for a mathematical expression.
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.
[in] | ev | interpreter |
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.
[in] | symbol_table | table of symbols |
[in] | str | label of the constant |
[in] | value | value associated to the constant |
hash_table_t* mei_table_symbols_new | ( | void | ) |
Returns a new table of symbols. The table contains standard mathematical symbols.
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.
[in] | ev | interpreter |
void mei_tree_destroy | ( | mei_tree_t * | ev | ) |
Free memory and return NULL.
[in] | ev | interpreter |
int mei_tree_find_symbol | ( | mei_tree_t * | ev, |
const char * | str | ||
) |
Check if the symbol str exists in the expression stored in ev.
[in] | ev | interpreter in which we want to know if str exists |
[in] | str | symbol to find |
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.
[in] | ev | interpreter |
[in] | size | number of symbols to check |
[in] | symbol | list of symbols |
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.
[in] | ev | interpreter |
[in] | str | label of the constant |
[in] | value | value associated to the constant |
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.
[in] | ev | interpreter |
[in] | str | name of the symbol |
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.
[in] | expr | string characters of the mathematical expression |
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.
[in] | expr | string characters of the mathematical expression |
[in] | symbol_table | shared table of symbols |