Mathematic Expressions Library  0.1
The core math data structures and manipulators
expression_lite.h File Reference
#include <stddef.h>
Include dependency graph for expression_lite.h:

Go to the source code of this file.

Typedefs

typedef struct expressionexpression_t
 

Functions

expression_t expression_new (void)
 New blank expression. More...
 
void expression_free (expression_t exp)
 Free an expression. More...
 
value_t expression_evaluate (expression_t exp)
 
void expression_to_string (char *dst_str, expression_t src_exp)
 Expression to String. More...
 
expression_t string_to_expression (size_t str_len, char const *str)
 Convert String to an Expression. More...
 

Detailed Description

Date
May 3, 2014
Author
Craig Hesling

Does not include any other project header file. This ensures that there are no circular dependencies.

Typedef Documentation

◆ expression_t

typedef struct expression* expression_t

Function Documentation

◆ expression_evaluate()

value_t expression_evaluate ( expression_t  exp)
Here is the call graph for this function:

◆ expression_free()

void expression_free ( expression_t  exp)

Free an expression.

Parameters
expThe expression to free
Here is the call graph for this function:

◆ expression_new()

expression_t expression_new ( void  )

New blank expression.

This function creates the most basic empty expression.

Returns
A new empty expression

◆ expression_to_string()

void expression_to_string ( char *  dst_str,
expression_t  src_exp 
)

Expression to String.

Here is the call graph for this function:

◆ string_to_expression()

expression_t string_to_expression ( size_t  str_len,
char const *  str 
)

Convert String to an Expression.

Parses a string into an expression.

Note
level was type int - changed to unsigned to temporarily quiet compiler
Bug:
Cannot parse negative numbers
Warning
Symbols must start with ALPHA chars to be properly identified.

Algorithm

Parsing Overview

  • Step 1: Recording details about the string while scanning from left to right.
  • Step 2: There are two real cases. The string is a single number (with no operations) or it is two sub-expressions joined by an operation.
    Cases:
    • If it is a simple number, we know how to parse it and create a value expression.
    • If it is not just a number, we want split the string about the operation at the lowest level. (in practice, we end up finding the one that is farthest left of the lowest level) We then construct a tree expression with the chosen operation and the sub-expression results from running the function recursively on each of the sub-strings.
Parameters
str_lenLength of given string
strString to parse
Returns
The expression_t representation of the inputed string
Test:
Test for negative values
Todo:
Allow symbols to be detected when they start with numeric digits also. string_to_sym is already compatible.

< Store original index

< Used to explore the presence of a symbol parameter

Todo:
Do series of additional syntax checks here.
Todo:
Syntax Check: Check that level==0
Todo:
Syntax Check: Check that oparen_count==cparen_count
Note
left_buf and right_buf were changed to use malloc to avoid errors with C90 compilers
Here is the call graph for this function: