#ifndef UNDAR_PARSER_H #define UNDAR_PARSER_H #include "libc.h" #include "lexer.h" typedef enum symbol_type_e { VOID, BOOL, I8, I16, I32, U8, U16, U32, F8, F16, F32, STR, ARRAY, FUNCTION, PLEX, METHOD, TRAIT, } SymbolType; typedef struct arena_list_s ArenaList; typedef struct symbol_s Symbol; typedef struct symbol_link_s SymbolLink; typedef struct token_stack_s TokenStack; typedef struct queue_s TokenQueue; typedef struct parser_s Parser; struct symbol_s { Token name; SymbolType type; u32 size; i32 scope; union type_def { struct trait_def { u32 field_ref_start; /* reference to field list of symbols */ u32 methods_ref_start; /* zero if none */ } trait; struct plex_def { u32 field_ref_start; /* reference to field list of symbols */ u32 methods_ref_start; /* zero if none */ } plex; struct function_def { SymbolType return_type; u32 arguments_ref_start; /* reference to field list of symbols */ } function; struct array_def { SymbolType type; u32 length; /* zero means "unbounded" */ } array; struct field_def { u32 offset; } field; } def; }; struct symbol_link_s { Symbol s; u32 cdr; /* zero means "end of list" */ }; struct arena_list_s { Arena *arena; u32 head; u32 tail; u32 size; u32 count; i32 parent; }; struct token_stack_s { Token *stack; i32 capacity; i32 count; }; struct queue_s { Token *queue; i32 capacity; i32 start; i32 end; i32 count; }; struct parser_s { Token current; Token previous; }; bool push(TokenStack *ts, Token t); Token pop(TokenStack *ts); Token top(TokenStack *ts); bool enqueue(TokenQueue *tq, Token t); Token dequeue(TokenQueue *tq); Token peek_queue(TokenQueue *tq); bool compile(char *source); #endif