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