Build an interpreter for a mathematical expression.  
More...
Go to the source code of this file.
|  | 
| struct | mei_tree_t | 
|  | Structure defining an interpreter for a mathematical expression.  More... 
 | 
|  | 
|  | 
| 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... 
 | 
|  | 
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. 
- Parameters
- 
  
  
- Returns
- value from the intrepreted expression 
 
 
      
        
          | 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_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. 
- Returns
- table of 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. 
- Parameters
- 
  
  
- Returns
- number of parsing errors 
 
 
      
        
          | void mei_tree_destroy | ( | mei_tree_t * | ev | ) |  | 
      
 
Free memory and return NULL. 
- Parameters
- 
  
  
 
 
      
        
          | 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] | ev | interpreter in which we want to know if str exists |  | [in] | str | symbol to find |  
 
- Returns
- 0 if the symbol exists in the symbol table, 1 if not 
 
 
      
        
          | 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] | ev | interpreter |  | [in] | size | number of symbols to check |  | [in] | symbol | list of symbols |  
 
- Returns
- 0 if all symbols exist, otherwise return the number of errors 
 
 
      
        
          | 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] | 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. 
- Parameters
- 
  
    | [in] | ev | interpreter |  | [in] | str | name of the symbol |  
 
- Returns
- value of a symbol 
 
 
      
        
          | mei_tree_t* mei_tree_new | ( | const char *const | 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] | expr | string characters of the mathematical expression |  
 
- Returns
- new empty interpreter 
 
 
      
        
          | 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] | expr | string characters of the mathematical expression |  | [in] | symbol_table | shared table of symbols |  
 
- Returns
- new empty interpreter