SO, i forgot to implement nud and led correctly and the parser cant tell apart from - as unary and - as binary (+ as well), i need to correct that, move Node * to TreeResult so to use NodeResult with nud and led
27 lines
521 B
C
27 lines
521 B
C
#ifndef EVALUATOR_H
|
|
#define EVALUATOR_H
|
|
|
|
#include "lexer.h"
|
|
#include "parser.h"
|
|
#include <stdint.h>
|
|
|
|
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;
|
|
|
|
EvaluatorResult evaluate(ParserResult context);
|
|
EvaluatorResult evaluate_tree(Node *tree);
|
|
|
|
#endif // !EVALUATOR_H
|