For now it works but i dont really like that i use ParseResult, i mean is necessary but i think i will try to make it cleaner so that i can just directly use like parse and pass tath into evaluate, that would require to move the main evaluate funciton into evaluate_tree or something and evaluate takes the arena, uses evaluate_tree and frees the arena, will try that the next commit but for now this version works perfectly.
36 lines
714 B
C
36 lines
714 B
C
#ifndef PARSER_H
|
|
#define PARSER_H
|
|
|
|
#include "lexer.h"
|
|
#include "arena.h"
|
|
#include <stdint.h>
|
|
|
|
typedef struct {
|
|
ASTNode *head;
|
|
} AST;
|
|
|
|
typedef struct {
|
|
ASTNodeArray *arr;
|
|
size_t pos;
|
|
} ASTNodeSlice;
|
|
|
|
typedef struct {
|
|
Arena *arena;
|
|
AST tree;
|
|
} ParseResult;
|
|
|
|
ASTNode ASTNodeSlice_peek(ASTNodeSlice *slice);
|
|
ASTNode ASTNodeSlice_next(ASTNodeSlice *slice);
|
|
bool ASTNodeSlice_is_valid(ASTNodeSlice *slice);
|
|
|
|
ASTNode *nud(ASTNodeSlice *slice);
|
|
ASTNode *led(ASTNodeSlice *slice, size_t right_precedence);
|
|
|
|
uint8_t node_lbp(ASTNode node);
|
|
uint8_t node_rbp(ASTNode node);
|
|
|
|
ParseResult parse(ASTNodeArray *arr);
|
|
ASTNode *parse_expr(ASTNodeSlice *slice, Arena *arena, uint8_t min_bp);
|
|
|
|
#endif // !PARSER_H
|