eTree_t* eParse

(eVariables_t* v, char* s, char** endpos, int* err,
  int newvars)

Parses expression and returns a pointer to an expression tree

Documentation

The function parses the string pointed to by s and builds an expression tree.

Anything that is neither a number nor a known operator is treated as a variable. New (previously unknown) variables are added to the v structure when newvars is true (greater than zero). Otherwise only known variables are accepted.

When no longer needed, the tree should be destroyed, and thus its memory freed, with eTreeDestroy().

Error value in *err SHOULD ALWAYS be checked. There are following error values:

EOK
ok, no error
ENUMBER
invalid number
EBINOP
unknown binary operator
EUNOP
unknown unary operator
EUNKNOWN
unknown token
EEND
unexpected end of expression
EEARLY
finished before the end of string
EPARENO
unmatched '('
EPARENC
unmatched ')'
EVAR
unknown variable
ETREE
error from eTreeInsert (internal error, this shouldn't happen)
EARG
wrong arguments

Parameters:
v - a pointer to eVariables_t structure. New variables are added to the structure.
s - a string that is to be parsed.
endpos - address of the last character that the function parsed.
err - a code of error if an error occured, otherwise 0 (EOK).
newvars - when greater than zero the parser will add new variables, when 0 it will accept only those already known.
Returns:
A pointer to newly created expression tree is returned. The function returns the address of the last parsed character in **endpos. If an error occurs, its code is stored in *err, otherwise its reset to 0.
See Also:
eTreeDestroy()

Alphabetic index


libsexpr - a simple library for parsing arithmetic expressions
© 2003 by Marcin Simonides