4 typedef struct eval_variable {
7 struct eval_variable *next;
10 typedef struct eval_expression {
12 const char *parsed_as;
14 calculated_number result;
22 // custom data to be used for looking up variables
26 #define EVAL_VALUE_INVALID 0
27 #define EVAL_VALUE_NUMBER 1
28 #define EVAL_VALUE_VARIABLE 2
29 #define EVAL_VALUE_EXPRESSION 3
31 #define EVAL_ERROR_OK 0
34 #define EVAL_ERROR_MISSING_CLOSE_SUBEXPRESSION 1
35 #define EVAL_ERROR_UNKNOWN_OPERAND 2
36 #define EVAL_ERROR_MISSING_OPERAND 3
37 #define EVAL_ERROR_MISSING_OPERATOR 4
40 #define EVAL_ERROR_INVALID_VALUE 5
41 #define EVAL_ERROR_INVALID_NUMBER_OF_OPERANDS 6
42 #define EVAL_ERROR_VALUE_IS_NAN 7
43 #define EVAL_ERROR_VALUE_IS_INFINITE 8
44 #define EVAL_ERROR_UNKNOWN_VARIABLE 9
46 // parse the given string as an expression and return:
47 // a pointer to an expression if it parsed OK
48 // NULL in which case the pointer to error has the error code
49 extern EVAL_EXPRESSION *expression_parse(const char *string, const char **failed_at, int *error);
51 // free all resources allocated for an expression
52 extern void expression_free(EVAL_EXPRESSION *op);
54 // convert an error code to a message
55 extern const char *expression_strerror(int error);
57 // evaluate an expression and return
58 // 1 = OK, the result is in: expression->result
59 // 2 = FAILED, the error message is in: buffer_tostring(expression->error_msg)
60 extern int expression_evaluate(EVAL_EXPRESSION *expression);
62 #endif //NETDATA_EVAL_H