refactor: changes and additions ot parser

This commit is contained in:
2026-05-12 18:15:36 -06:00
parent c41847e120
commit 59f99059bb
5 changed files with 57 additions and 11 deletions

View File

@@ -10,6 +10,7 @@
typedef enum {
NODE_INTEGER,
NODE_BINARY_OP,
NODE_UNARY_OP,
} ASTNodeType;
// For classify operators
@@ -17,7 +18,8 @@ typedef enum {
OP_ADD,
OP_SUB,
OP_MUL,
OP_DIV
OP_DIV,
OP_POW,
} Operator;
typedef enum {
@@ -26,8 +28,6 @@ typedef enum {
LEXER_FAILED_NUMBER_CONVERSION,
LEXER_NOT_RECOGNIZED_SYMBOL,
LEXER_EMPTY_INPUT,
LEXER_NULL_ARG,
LEXER_WRONG_SYNTAX,
LEXER_BUF_OVERFLOW,
} LexerErr;
@@ -41,6 +41,10 @@ typedef struct ASTNode {
struct ASTNode *right;
Operator op;
} binary;
struct {
struct ASTNode *val;
Operator op;
} unary;
} data;
} ASTNode;

View File

@@ -32,8 +32,10 @@ typedef struct {
ASTNode *nud(ArraySlice *slice);
ASTNode *led(ArraySlice *slice, size_t right_precedence);
uint8_t node_lbp(ASTNode node);
uint8_t node_rbp(ASTNode node);
uint8_t prefix_lbp(ASTNode node);
uint8_t prefix_rbp(ASTNode node);
uint8_t infix_lbp(ASTNode node);
uint8_t infix_rbp(ASTNode node);
ParseResult parse(TokenizeResult tokens);
ASTNode *parse_expr(ArraySlice *slice, Arena *arena, uint8_t min_bp);