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
38 #define EVAL_ERROR_REMAINING_GARBAGE 5
41 #define EVAL_ERROR_INVALID_VALUE 11
42 #define EVAL_ERROR_INVALID_NUMBER_OF_OPERANDS 12
43 #define EVAL_ERROR_VALUE_IS_NAN 13
44 #define EVAL_ERROR_VALUE_IS_INFINITE 14
45 #define EVAL_ERROR_UNKNOWN_VARIABLE 15
47 // parse the given string as an expression and return:
48 // a pointer to an expression if it parsed OK
49 // NULL in which case the pointer to error has the error code
50 extern EVAL_EXPRESSION *expression_parse(const char *string, const char **failed_at, int *error);
52 // free all resources allocated for an expression
53 extern void expression_free(EVAL_EXPRESSION *op);
55 // convert an error code to a message
56 extern const char *expression_strerror(int error);
58 // evaluate an expression and return
59 // 1 = OK, the result is in: expression->result
60 // 2 = FAILED, the error message is in: buffer_tostring(expression->error_msg)
61 extern int expression_evaluate(EVAL_EXPRESSION *expression);
63 #endif //NETDATA_EVAL_H