refactor-error-handling #12

Merged
laentropia merged 11 commits from refactor-error-handling into main 2026-05-13 19:05:55 -06:00
Showing only changes of commit 2a73f5f9d6 - Show all commits

View File

@@ -8,12 +8,9 @@
// For identifing
typedef enum {
NODE_INTEGER,
NODE_BINARY_OP,
NODE_UNARY_OP,
NODE_PARENTHESIS,
} ASTNodeType;
TOKEN_INTEGER,
TOKEN_OPERATOR,
} TokenType;
// For classify operators
typedef enum {
OP_ADD,
@@ -36,25 +33,13 @@ typedef enum {
} LexerErr;
// Can be thought as tokens, they will be used by the parser.
typedef struct ASTNode {
ASTNodeType type;
typedef struct {
TokenType type;
union {
int64_t integer;
struct {
struct ASTNode *left;
struct ASTNode *right;
int64_t num;
Operator op;
} binary;
struct {
struct ASTNode *val;
Operator op;
} unary;
struct {
struct ASTNode *val;
Operator op;
} parenthesis;
} data;
} ASTNode;
};
} Token;
typedef struct {
bool is_valid;
@@ -68,9 +53,9 @@ typedef struct {
bool is_valid;
union {
LexerErr err;
ASTNode node;
Token token;
};
} ASTNodeResult;
} TokenResult;
typedef struct {
bool is_valid;
@@ -82,7 +67,7 @@ typedef struct {
// Lexer funtions as well as few functionality
TokenizeResult tokenize(const char* input);
ASTNodeResult tokenize_number(const char* input, size_t *offset);
TokenResult tokenize_number(const char* input, size_t *offset);
LexerI64Result string_to_integer(const char buf[]);
bool isoperator(int c);
Operator char_to_operator(int c);