blob: a645b31b07896e7c7ee871594c6b6c7ac171f549 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
#ifndef NETDATA_EVAL_H
#define NETDATA_EVAL_H
typedef struct variable {
char *name;
struct rrdvar *rrdvar;
struct variable *next;
} VARIABLE;
#define EVAL_VALUE_INVALID 0
#define EVAL_VALUE_NUMBER 1
#define EVAL_VALUE_VARIABLE 2
#define EVAL_VALUE_EXPRESSION 3
// these are used for EVAL_NODE.operator
#define EVAL_OPERATOR_NOP '\0'
#define EVAL_OPERATOR_VALUE ':'
#define EVAL_OPERATOR_EXPRESSION_OPEN '('
#define EVAL_OPERATOR_EXPRESSION_CLOSE ')'
#define EVAL_OPERATOR_NOT '!'
#define EVAL_OPERATOR_PLUS '+'
#define EVAL_OPERATOR_MINUS '-'
#define EVAL_OPERATOR_AND '&'
#define EVAL_OPERATOR_OR '|'
#define EVAL_OPERATOR_GREATER_THAN_OR_EQUAL 'G'
#define EVAL_OPERATOR_LESS_THAN_OR_EQUAL 'L'
#define EVAL_OPERATOR_NOT_EQUAL '~'
#define EVAL_OPERATOR_EQUAL '='
#define EVAL_OPERATOR_LESS '<'
#define EVAL_OPERATOR_GREATER '>'
#define EVAL_OPERATOR_MULTIPLY '*'
#define EVAL_OPERATOR_DIVIDE '/'
#define EVAL_OPERATOR_SIGN_PLUS 'P'
#define EVAL_OPERATOR_SIGN_MINUS 'M'
#define EVAL_ERROR_OK 0
// parsing errors
#define EVAL_ERROR_MISSING_CLOSE_SUBEXPRESSION 1
#define EVAL_ERROR_UNKNOWN_OPERAND 2
#define EVAL_ERROR_MISSING_OPERAND 3
#define EVAL_ERROR_MISSING_OPERATOR 4
// evaluation errors
#define EVAL_ERROR_INVALID_VALUE 5
#define EVAL_ERROR_INVALID_NUMBER_OF_OPERANDS 6
#define EVAL_ERROR_VALUE_IS_NAN 7
#define EVAL_ERROR_VALUE_IS_INFINITE 8
typedef struct eval_value {
int type;
union {
calculated_number number;
VARIABLE *variable;
struct eval_node *expression;
};
} EVAL_VALUE;
typedef struct eval_node {
int id;
unsigned char operator;
int precedence;
int count;
EVAL_VALUE ops[];
} EVAL_NODE;
extern EVAL_NODE *expression_parse(const char *string, const char **failed_at, int *error);
extern calculated_number expression_evaluate(EVAL_NODE *expression, int *error);
extern void expression_free(EVAL_NODE *op);
extern const char *expression_strerror(int error);
#endif //NETDATA_EVAL_H
|