refactor: evaluator incomplete.

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
This commit is contained in:
2026-05-13 12:13:07 -06:00
parent 542a94ef81
commit efa0e3bacd
5 changed files with 111 additions and 20 deletions

View File

@@ -5,7 +5,22 @@
#include "parser.h"
#include <stdint.h>
int64_t evaluate(ParseResult context);
int64_t evaluate_tree(ASTNode *tree);
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

View File

@@ -37,6 +37,7 @@ typedef enum {
PARSER_MISSING_OPERAND,
PARSER_UNMATCHED_PAREN,
PARSER_OUT_OF_MEMORY,
PARSER_INVALID_TOKENIZE,
} ParserErr;
typedef struct {