2026-03-25 11:30:12 -06:00
|
|
|
#ifndef EVALUATOR_H
|
|
|
|
|
#define EVALUATOR_H
|
|
|
|
|
|
2026-04-13 08:44:30 -06:00
|
|
|
#include "parser.h"
|
2026-03-25 11:30:12 -06:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
2026-05-13 12:13:07 -06:00
|
|
|
typedef enum {
|
|
|
|
|
EVALUATOR_OK,
|
|
|
|
|
EVALUATOR_MATH_ERR,
|
|
|
|
|
EVALUATOR_INVALID_PARSING,
|
|
|
|
|
EVALUATOR_INVALID_TREE, // just to shut up the compiler with the swithces
|
|
|
|
|
} EvaluatorErr;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
bool is_valid;
|
|
|
|
|
union {
|
|
|
|
|
int64_t val;
|
|
|
|
|
EvaluatorErr err;
|
|
|
|
|
};
|
|
|
|
|
} EvaluatorResult;
|
|
|
|
|
|
2026-05-13 18:06:01 -06:00
|
|
|
EvaluatorResult evaluate_binary(Node *tree);
|
|
|
|
|
EvaluatorResult evaluate_unary(Node *tree);
|
|
|
|
|
|
2026-05-13 12:13:07 -06:00
|
|
|
EvaluatorResult evaluate(ParserResult context);
|
|
|
|
|
EvaluatorResult evaluate_tree(Node *tree);
|
2026-03-25 11:30:12 -06:00
|
|
|
|
|
|
|
|
#endif // !EVALUATOR_H
|