3 // ----------------------------------------------------------------------------
4 // data structures for storing the parsed expression in memory
6 typedef struct eval_value {
10 calculated_number number;
11 EVAL_VARIABLE *variable;
12 struct eval_node *expression;
16 typedef struct eval_node {
18 unsigned char operator;
25 // these are used for EVAL_NODE.operator
26 // they are used as internal IDs to identify an operator
27 // THEY ARE NOT USED FOR PARSING OPERATORS LIKE THAT
28 #define EVAL_OPERATOR_NOP '\0'
29 #define EVAL_OPERATOR_VALUE ':'
30 #define EVAL_OPERATOR_EXPRESSION_OPEN '('
31 #define EVAL_OPERATOR_EXPRESSION_CLOSE ')'
32 #define EVAL_OPERATOR_NOT '!'
33 #define EVAL_OPERATOR_PLUS '+'
34 #define EVAL_OPERATOR_MINUS '-'
35 #define EVAL_OPERATOR_AND '&'
36 #define EVAL_OPERATOR_OR '|'
37 #define EVAL_OPERATOR_GREATER_THAN_OR_EQUAL 'G'
38 #define EVAL_OPERATOR_LESS_THAN_OR_EQUAL 'L'
39 #define EVAL_OPERATOR_NOT_EQUAL '~'
40 #define EVAL_OPERATOR_EQUAL '='
41 #define EVAL_OPERATOR_LESS '<'
42 #define EVAL_OPERATOR_GREATER '>'
43 #define EVAL_OPERATOR_MULTIPLY '*'
44 #define EVAL_OPERATOR_DIVIDE '/'
45 #define EVAL_OPERATOR_SIGN_PLUS 'P'
46 #define EVAL_OPERATOR_SIGN_MINUS 'M'
48 // ----------------------------------------------------------------------------
49 // forward function definitions
51 static inline void eval_node_free(EVAL_NODE *op);
52 static inline EVAL_NODE *parse_full_expression(const char **string, int *error);
53 static inline EVAL_NODE *parse_one_full_operand(const char **string, int *error);
54 static inline calculated_number eval_node(EVAL_EXPRESSION *exp, EVAL_NODE *op, int *error);
55 static inline void print_parsed_as_node(BUFFER *out, EVAL_NODE *op, int *error);
57 // ----------------------------------------------------------------------------
58 // evaluation of expressions
60 static inline calculated_number eval_check_number(calculated_number n, int *error) {
61 if(unlikely(isnan(n))) {
62 *error = EVAL_ERROR_VALUE_IS_NAN;
66 if(unlikely(isinf(n))) {
67 *error = EVAL_ERROR_VALUE_IS_INFINITE;
74 static inline calculated_number eval_variable(EVAL_EXPRESSION *exp, EVAL_VARIABLE *v, int *error) {
75 // FIXME: do the variable look up here
78 *error = EVAL_ERROR_UNKNOWN_VARIABLE;
79 buffer_sprintf(exp->error_msg, "unknown variable '%s'", v->name);
85 static inline calculated_number eval_value(EVAL_EXPRESSION *exp, EVAL_VALUE *v, int *error) {
89 case EVAL_VALUE_EXPRESSION:
90 n = eval_node(exp, v->expression, error);
93 case EVAL_VALUE_NUMBER:
97 case EVAL_VALUE_VARIABLE:
98 n = eval_variable(exp, v->variable, error);
102 *error = EVAL_ERROR_INVALID_VALUE;
107 return eval_check_number(n, error);
110 calculated_number eval_and(EVAL_EXPRESSION *exp, EVAL_NODE *op, int *error) {
111 return eval_value(exp, &op->ops[0], error) && eval_value(exp, &op->ops[1], error);
113 calculated_number eval_or(EVAL_EXPRESSION *exp, EVAL_NODE *op, int *error) {
114 return eval_value(exp, &op->ops[0], error) || eval_value(exp, &op->ops[1], error);
116 calculated_number eval_greater_than_or_equal(EVAL_EXPRESSION *exp, EVAL_NODE *op, int *error) {
117 return eval_value(exp, &op->ops[0], error) >= eval_value(exp, &op->ops[1], error);
119 calculated_number eval_less_than_or_equal(EVAL_EXPRESSION *exp, EVAL_NODE *op, int *error) {
120 return eval_value(exp, &op->ops[0], error) <= eval_value(exp, &op->ops[1], error);
122 calculated_number eval_not_equal(EVAL_EXPRESSION *exp, EVAL_NODE *op, int *error) {
123 return eval_value(exp, &op->ops[0], error) != eval_value(exp, &op->ops[1], error);
125 calculated_number eval_equal(EVAL_EXPRESSION *exp, EVAL_NODE *op, int *error) {
126 return eval_value(exp, &op->ops[0], error) == eval_value(exp, &op->ops[1], error);
128 calculated_number eval_less(EVAL_EXPRESSION *exp, EVAL_NODE *op, int *error) {
129 return eval_value(exp, &op->ops[0], error) < eval_value(exp, &op->ops[1], error);
131 calculated_number eval_greater(EVAL_EXPRESSION *exp, EVAL_NODE *op, int *error) {
132 return eval_value(exp, &op->ops[0], error) > eval_value(exp, &op->ops[1], error);
134 calculated_number eval_plus(EVAL_EXPRESSION *exp, EVAL_NODE *op, int *error) {
135 return eval_value(exp, &op->ops[0], error) + eval_value(exp, &op->ops[1], error);
137 calculated_number eval_minus(EVAL_EXPRESSION *exp, EVAL_NODE *op, int *error) {
138 return eval_value(exp, &op->ops[0], error) - eval_value(exp, &op->ops[1], error);
140 calculated_number eval_multiply(EVAL_EXPRESSION *exp, EVAL_NODE *op, int *error) {
141 return eval_value(exp, &op->ops[0], error) * eval_value(exp, &op->ops[1], error);
143 calculated_number eval_divide(EVAL_EXPRESSION *exp, EVAL_NODE *op, int *error) {
144 return eval_value(exp, &op->ops[0], error) / eval_value(exp, &op->ops[1], error);
146 calculated_number eval_nop(EVAL_EXPRESSION *exp, EVAL_NODE *op, int *error) {
147 return eval_value(exp, &op->ops[0], error);
149 calculated_number eval_not(EVAL_EXPRESSION *exp, EVAL_NODE *op, int *error) {
150 return !eval_value(exp, &op->ops[0], error);
152 calculated_number eval_sign_plus(EVAL_EXPRESSION *exp, EVAL_NODE *op, int *error) {
153 return eval_value(exp, &op->ops[0], error);
155 calculated_number eval_sign_minus(EVAL_EXPRESSION *exp, EVAL_NODE *op, int *error) {
156 return -eval_value(exp, &op->ops[0], error);
159 static struct operator {
160 const char *print_as;
163 calculated_number (*eval)(EVAL_EXPRESSION *exp, EVAL_NODE *op, int *error);
165 // this is a random access array
166 // we always access it with a known EVAL_OPERATOR_X
168 [EVAL_OPERATOR_AND] = { "&&", 2, 2, eval_and },
169 [EVAL_OPERATOR_OR] = { "||", 2, 2, eval_or },
170 [EVAL_OPERATOR_GREATER_THAN_OR_EQUAL] = { ">=", 3, 2, eval_greater_than_or_equal },
171 [EVAL_OPERATOR_LESS_THAN_OR_EQUAL] = { "<=", 3, 2, eval_less_than_or_equal },
172 [EVAL_OPERATOR_NOT_EQUAL] = { "!=", 3, 2, eval_not_equal },
173 [EVAL_OPERATOR_EQUAL] = { "==", 3, 2, eval_equal },
174 [EVAL_OPERATOR_LESS] = { "<", 3, 2, eval_less },
175 [EVAL_OPERATOR_GREATER] = { ">", 3, 2, eval_greater },
176 [EVAL_OPERATOR_PLUS] = { "+", 4, 2, eval_plus },
177 [EVAL_OPERATOR_MINUS] = { "-", 4, 2, eval_minus },
178 [EVAL_OPERATOR_MULTIPLY] = { "*", 5, 2, eval_multiply },
179 [EVAL_OPERATOR_DIVIDE] = { "/", 5, 2, eval_divide },
180 [EVAL_OPERATOR_NOT] = { "!", 6, 1, eval_not },
181 [EVAL_OPERATOR_SIGN_PLUS] = { "+", 6, 1, eval_sign_plus },
182 [EVAL_OPERATOR_SIGN_MINUS] = { "-", 6, 1, eval_sign_minus },
183 [EVAL_OPERATOR_NOP] = { NULL, 7, 1, eval_nop },
184 [EVAL_OPERATOR_VALUE] = { NULL, 7, 1, eval_nop },
185 [EVAL_OPERATOR_EXPRESSION_OPEN] = { NULL, 7, 1, eval_nop },
187 // this should exist in our evaluation list
188 [EVAL_OPERATOR_EXPRESSION_CLOSE] = { NULL, 7, 1, eval_nop }
191 #define eval_precedence(operator) (operators[(unsigned char)(operator)].precedence)
193 static inline calculated_number eval_node(EVAL_EXPRESSION *exp, EVAL_NODE *op, int *error) {
194 if(unlikely(op->count != operators[op->operator].parameters)) {
195 *error = EVAL_ERROR_INVALID_NUMBER_OF_OPERANDS;
199 calculated_number n = operators[op->operator].eval(exp, op, error);
201 return eval_check_number(n, error);
204 // ----------------------------------------------------------------------------
205 // parsed-as generation
207 static inline void print_parsed_as_variable(BUFFER *out, EVAL_VARIABLE *v, int *error) {
209 buffer_sprintf(out, "$%s", v->name);
212 static inline void print_parsed_as_constant(BUFFER *out, calculated_number n) {
214 snprintfz(b, 100, CALCULATED_NUMBER_FORMAT, n);
216 s = &b[strlen(b) - 1];
217 while(s > b && *s == '0') {
222 if(s > b && *s == '.')
225 buffer_strcat(out, b);
228 static inline void print_parsed_as_value(BUFFER *out, EVAL_VALUE *v, int *error) {
230 case EVAL_VALUE_EXPRESSION:
231 print_parsed_as_node(out, v->expression, error);
234 case EVAL_VALUE_NUMBER:
235 print_parsed_as_constant(out, v->number);
238 case EVAL_VALUE_VARIABLE:
239 print_parsed_as_variable(out, v->variable, error);
243 *error = EVAL_ERROR_INVALID_VALUE;
248 static inline void print_parsed_as_node(BUFFER *out, EVAL_NODE *op, int *error) {
249 if(unlikely(op->count != operators[op->operator].parameters)) {
250 *error = EVAL_ERROR_INVALID_NUMBER_OF_OPERANDS;
254 if(operators[op->operator].parameters == 1) {
256 if(operators[op->operator].print_as)
257 buffer_sprintf(out, "%s", operators[op->operator].print_as);
259 //if(op->operator == EVAL_OPERATOR_EXPRESSION_OPEN)
260 // buffer_strcat(out, "(");
262 print_parsed_as_value(out, &op->ops[0], error);
264 //if(op->operator == EVAL_OPERATOR_EXPRESSION_OPEN)
265 // buffer_strcat(out, ")");
268 else if(operators[op->operator].parameters == 2) {
269 buffer_strcat(out, "(");
270 print_parsed_as_value(out, &op->ops[0], error);
272 if(operators[op->operator].print_as)
273 buffer_sprintf(out, " %s ", operators[op->operator].print_as);
275 print_parsed_as_value(out, &op->ops[1], error);
276 buffer_strcat(out, ")");
280 // ----------------------------------------------------------------------------
281 // parsing expressions
284 static inline void skip_spaces(const char **string) {
285 const char *s = *string;
286 while(isspace(*s)) s++;
290 // what character can appear just after an operator keyword
292 static inline int isoperatorterm_word(const char s) {
293 if(isspace(s) || s == '(' || s == '$' || s == '!' || s == '-' || s == '+' || isdigit(s) || !s)
299 // what character can appear just after an operator symbol?
300 static inline int isoperatorterm_symbol(const char s) {
301 if(isoperatorterm_word(s) || isalpha(s)) return 1;
305 // ----------------------------------------------------------------------------
308 static inline int parse_and(const char **string) {
309 const char *s = *string;
312 if((s[0] == 'A' || s[0] == 'a') && (s[1] == 'N' || s[1] == 'n') && (s[2] == 'D' || s[2] == 'd') && isoperatorterm_word(s[3])) {
318 if(s[0] == '&' && s[1] == '&' && isoperatorterm_symbol(s[2])) {
326 static inline int parse_or(const char **string) {
327 const char *s = *string;
330 if((s[0] == 'O' || s[0] == 'o') && (s[1] == 'R' || s[1] == 'r') && isoperatorterm_word(s[2])) {
336 if(s[0] == '|' && s[1] == '|' && isoperatorterm_symbol(s[2])) {
344 static inline int parse_greater_than_or_equal(const char **string) {
345 const char *s = *string;
348 if(s[0] == '>' && s[1] == '=' && isoperatorterm_symbol(s[2])) {
356 static inline int parse_less_than_or_equal(const char **string) {
357 const char *s = *string;
360 if (s[0] == '<' && s[1] == '=' && isoperatorterm_symbol(s[2])) {
368 static inline int parse_greater(const char **string) {
369 const char *s = *string;
372 if(s[0] == '>' && isoperatorterm_symbol(s[1])) {
380 static inline int parse_less(const char **string) {
381 const char *s = *string;
384 if(s[0] == '<' && isoperatorterm_symbol(s[1])) {
392 static inline int parse_equal(const char **string) {
393 const char *s = *string;
396 if(s[0] == '=' && s[1] == '=' && isoperatorterm_symbol(s[2])) {
402 if(s[0] == '=' && isoperatorterm_symbol(s[1])) {
410 static inline int parse_not_equal(const char **string) {
411 const char *s = *string;
414 if(s[0] == '!' && s[1] == '=' && isoperatorterm_symbol(s[2])) {
420 if(s[0] == '<' && s[1] == '>' && isoperatorterm_symbol(s[2])) {
427 static inline int parse_not(const char **string) {
428 const char *s = *string;
431 if((s[0] == 'N' || s[0] == 'n') && (s[1] == 'O' || s[1] == 'o') && (s[2] == 'T' || s[2] == 't') && isoperatorterm_word(s[3])) {
444 static inline int parse_multiply(const char **string) {
445 const char *s = *string;
448 if(s[0] == '*' && isoperatorterm_symbol(s[1])) {
456 static inline int parse_divide(const char **string) {
457 const char *s = *string;
460 if(s[0] == '/' && isoperatorterm_symbol(s[1])) {
468 static inline int parse_minus(const char **string) {
469 const char *s = *string;
472 if(s[0] == '-' && isoperatorterm_symbol(s[1])) {
480 static inline int parse_plus(const char **string) {
481 const char *s = *string;
484 if(s[0] == '+' && isoperatorterm_symbol(s[1])) {
492 static inline int parse_open_subexpression(const char **string) {
493 const char *s = *string;
504 static inline int parse_close_subexpression(const char **string) {
505 const char *s = *string;
516 static inline int parse_constant(const char **string, calculated_number *number) {
518 calculated_number n = strtold(*string, &end);
519 if(unlikely(!end || *string == end || isnan(n) || isinf(n))) {
528 static struct operator_parser {
530 int (*parse)(const char **);
531 } operator_parsers[] = {
532 // the order in this list is important!
533 // the first matching will be used
534 // so place the longer of overlapping ones
537 { EVAL_OPERATOR_AND, parse_and },
538 { EVAL_OPERATOR_OR, parse_or },
539 { EVAL_OPERATOR_GREATER_THAN_OR_EQUAL, parse_greater_than_or_equal },
540 { EVAL_OPERATOR_LESS_THAN_OR_EQUAL, parse_less_than_or_equal },
541 { EVAL_OPERATOR_NOT_EQUAL, parse_not_equal },
542 { EVAL_OPERATOR_EQUAL, parse_equal },
543 { EVAL_OPERATOR_LESS, parse_less },
544 { EVAL_OPERATOR_GREATER, parse_greater },
545 { EVAL_OPERATOR_PLUS, parse_plus },
546 { EVAL_OPERATOR_MINUS, parse_minus },
547 { EVAL_OPERATOR_MULTIPLY, parse_multiply },
548 { EVAL_OPERATOR_DIVIDE, parse_divide },
550 /* we should not put in this list the following:
556 * these are handled in code
560 { EVAL_OPERATOR_NOP, NULL }
563 static inline unsigned char parse_operator(const char **string, int *precedence) {
567 for(i = 0 ; operator_parsers[i].parse != NULL ; i++)
568 if(operator_parsers[i].parse(string)) {
569 if(precedence) *precedence = eval_precedence(operator_parsers[i].id);
570 return operator_parsers[i].id;
573 return EVAL_OPERATOR_NOP;
576 // ----------------------------------------------------------------------------
579 static inline EVAL_NODE *eval_node_alloc(int count) {
582 EVAL_NODE *op = calloc(1, sizeof(EVAL_NODE) + (sizeof(EVAL_VALUE) * count));
583 if(!op) fatal("Cannot allocate memory for OPERAND with %d slots", count);
586 op->operator = EVAL_OPERATOR_NOP;
587 op->precedence = eval_precedence(EVAL_OPERATOR_NOP);
592 static inline void eval_node_set_value_to_node(EVAL_NODE *op, int pos, EVAL_NODE *value) {
594 fatal("Invalid request to set position %d of OPERAND that has only %d values", pos + 1, op->count + 1);
596 op->ops[pos].type = EVAL_VALUE_EXPRESSION;
597 op->ops[pos].expression = value;
600 static inline void eval_node_set_value_to_constant(EVAL_NODE *op, int pos, calculated_number value) {
602 fatal("Invalid request to set position %d of OPERAND that has only %d values", pos + 1, op->count + 1);
604 op->ops[pos].type = EVAL_VALUE_NUMBER;
605 op->ops[pos].number = value;
608 static inline void eval_variable_free(EVAL_VARIABLE *v) {
612 static inline void eval_value_free(EVAL_VALUE *v) {
614 case EVAL_VALUE_EXPRESSION:
615 eval_node_free(v->expression);
618 case EVAL_VALUE_VARIABLE:
619 eval_variable_free(v->variable);
627 static inline void eval_node_free(EVAL_NODE *op) {
630 for(i = op->count - 1; i >= 0 ;i--)
631 eval_value_free(&op->ops[i]);
637 // ----------------------------------------------------------------------------
640 // helper function to avoid allocations all over the place
641 static inline EVAL_NODE *parse_next_operand_given_its_operator(const char **string, unsigned char operator_type, int *error) {
642 EVAL_NODE *sub = parse_one_full_operand(string, error);
643 if(!sub) return NULL;
645 EVAL_NODE *op = eval_node_alloc(1);
646 op->operator = operator_type;
647 eval_node_set_value_to_node(op, 0, sub);
651 // parse a full operand, including its sign or other associative operator (e.g. NOT)
652 static inline EVAL_NODE *parse_one_full_operand(const char **string, int *error) {
653 EVAL_NODE *op1 = NULL;
654 calculated_number number;
656 *error = EVAL_ERROR_OK;
660 *error = EVAL_ERROR_MISSING_OPERAND;
664 if(parse_not(string)) {
665 op1 = parse_next_operand_given_its_operator(string, EVAL_OPERATOR_NOT, error);
666 op1->precedence = eval_precedence(EVAL_OPERATOR_NOT);
668 else if(parse_plus(string)) {
669 op1 = parse_next_operand_given_its_operator(string, EVAL_OPERATOR_SIGN_PLUS, error);
670 op1->precedence = eval_precedence(EVAL_OPERATOR_SIGN_PLUS);
672 else if(parse_minus(string)) {
673 op1 = parse_next_operand_given_its_operator(string, EVAL_OPERATOR_SIGN_MINUS, error);
674 op1->precedence = eval_precedence(EVAL_OPERATOR_SIGN_MINUS);
676 else if(parse_open_subexpression(string)) {
677 EVAL_NODE *sub = parse_full_expression(string, error);
679 op1 = eval_node_alloc(1);
680 op1->operator = EVAL_OPERATOR_EXPRESSION_OPEN;
681 op1->precedence = eval_precedence(EVAL_OPERATOR_EXPRESSION_OPEN);
682 eval_node_set_value_to_node(op1, 0, sub);
683 if(!parse_close_subexpression(string)) {
684 *error = EVAL_ERROR_MISSING_CLOSE_SUBEXPRESSION;
690 // else if(parse_variable(string)) {
693 else if(parse_constant(string, &number)) {
694 op1 = eval_node_alloc(1);
695 op1->operator = EVAL_OPERATOR_VALUE;
696 eval_node_set_value_to_constant(op1, 0, number);
699 *error = EVAL_ERROR_UNKNOWN_OPERAND;
701 *error = EVAL_ERROR_MISSING_OPERAND;
706 // parse an operator and the rest of the expression
707 // precedence processing is handled here
708 static inline EVAL_NODE *parse_rest_of_expression(const char **string, int *error, EVAL_NODE *op1) {
709 EVAL_NODE *op2 = NULL;
710 unsigned char operator;
713 operator = parse_operator(string, &precedence);
716 if(operator != EVAL_OPERATOR_NOP) {
717 op2 = parse_one_full_operand(string, error);
719 // error is already reported
724 EVAL_NODE *op = eval_node_alloc(2);
725 op->operator = operator;
726 op->precedence = precedence;
728 eval_node_set_value_to_node(op, 1, op2);
730 // precedence processing
731 // if this operator has a higher precedence compared to its next
732 // put the next operator on top of us (top = evaluated later)
733 // function recursion does the rest...
734 if(op->precedence > op1->precedence && op1->count == 2 && op1->operator != '(' && op1->ops[1].type == EVAL_VALUE_EXPRESSION) {
735 eval_node_set_value_to_node(op, 0, op1->ops[1].expression);
736 op1->ops[1].expression = op;
740 eval_node_set_value_to_node(op, 0, op1);
742 return parse_rest_of_expression(string, error, op);
744 else if(**string == ')') {
748 if(op1) eval_node_free(op1);
750 *error = EVAL_ERROR_MISSING_OPERATOR;
756 // high level function to parse an expression or a sub-expression
757 static inline EVAL_NODE *parse_full_expression(const char **string, int *error) {
758 EVAL_NODE *op1 = NULL;
760 op1 = parse_one_full_operand(string, error);
762 *error = EVAL_ERROR_MISSING_OPERAND;
766 return parse_rest_of_expression(string, error, op1);
769 // ----------------------------------------------------------------------------
772 int expression_evaluate(EVAL_EXPRESSION *exp) {
773 exp->error = EVAL_ERROR_OK;
775 buffer_reset(exp->error_msg);
776 exp->result = eval_node(exp, (EVAL_NODE *)exp->nodes, &exp->error);
778 if(exp->error != EVAL_ERROR_OK) {
779 if(buffer_strlen(exp->error_msg))
780 buffer_strcat(exp->error_msg, "; ");
782 buffer_sprintf(exp->error_msg, "failed to evaluate expression with error %d (%s)", exp->error, expression_strerror(exp->error));
789 EVAL_EXPRESSION *expression_parse(const char *string, const char **failed_at, int *error) {
791 int err = EVAL_ERROR_OK;
792 unsigned long pos = 0;
795 EVAL_NODE *op = parse_full_expression(&s, &err);
802 err = EVAL_ERROR_REMAINING_GARBAGE;
805 if (failed_at) *failed_at = s;
806 if (error) *error = err;
809 pos = s - string + 1;
810 error("failed to parse expression '%s': %s at character %lu (i.e.: '%s').", string, expression_strerror(err), pos, s);
814 BUFFER *out = buffer_create(1024);
815 print_parsed_as_node(out, op, &err);
816 if(err != EVAL_ERROR_OK) {
817 error("failed to re-generate expression '%s' with reason: %s", string, expression_strerror(err));
823 EVAL_EXPRESSION *exp = calloc(1, sizeof(EVAL_EXPRESSION));
824 if(!exp) fatal("Cannot allocate EVAL_EXPRESSION");
826 exp->parsed_as = strdup(buffer_tostring(out));
827 if(!exp->parsed_as) fatal("Cannot allocate memory for parsed-as string");
830 exp->error_msg = buffer_create(100);
831 exp->nodes = (void *)op;
836 void expression_free(EVAL_EXPRESSION *exp) {
839 if(exp->nodes) eval_node_free((EVAL_NODE *)exp->nodes);
840 free((void *)exp->source);
841 free((void *)exp->parsed_as);
842 buffer_free(exp->error_msg);
846 const char *expression_strerror(int error) {
851 case EVAL_ERROR_MISSING_CLOSE_SUBEXPRESSION:
852 return "missing closing parenthesis";
854 case EVAL_ERROR_UNKNOWN_OPERAND:
855 return "unknown operand";
857 case EVAL_ERROR_MISSING_OPERAND:
858 return "expected operand";
860 case EVAL_ERROR_MISSING_OPERATOR:
861 return "expected operator";
863 case EVAL_ERROR_REMAINING_GARBAGE:
864 return "remaining characters after expression";
866 case EVAL_ERROR_INVALID_VALUE:
867 return "invalid value structure - internal error";
869 case EVAL_ERROR_INVALID_NUMBER_OF_OPERANDS:
870 return "wrong number of operands for operation - internal error";
872 case EVAL_ERROR_VALUE_IS_NAN:
873 return "value or variable is missing or is not a number";
875 case EVAL_ERROR_VALUE_IS_INFINITE:
876 return "computed value is infinite";
878 case EVAL_ERROR_UNKNOWN_VARIABLE:
879 return "undefined variable";
882 return "unknown error";