#include "parser.h" Parser parser; bool advance() { parser.previous = parser.current; for(;;) { parser.current = next_token(); if(parser.current.type != TOKEN_ERROR) return true; return false; } } /**************************************************** * Scope ***************************************************/ void scope_push(Arena *arena) { Scope *child = aalloc(arena, sizeof(Scope)); child->symbols = new_list(arena); child->parent = parser.current_scope; parser.current_scope = child; } void scope_pop(Arena *arena) { Scope *prev = parser.current_scope->parent; parser.current_scope = prev; } Symbol * scope_get_symbol(Scope *scope, const char *name, u32 name_length) { if (!scope) return nil; u32 count = scope->symbols->count; for (u32 i = 0; i < count; i++) { Symbol *sym = list_get(scope->symbols, i); if (sleq(sym->name, name, name_length)) { return sym; } } return scope_get_symbol(scope->parent, name, name_length); } Symbol * scope_add_symbol(Arena *arena, const char *name, u32 name_length, SymbolType type, u32 size) { Symbol *sym = scope_get_symbol(parser.current_scope, name, name_length); if (sym != nil) return sym; sym = aalloc(arena, sizeof(Symbol)); scpy(sym->name, name, slen(name)); sym->name_length = slen(name); sym->type = type; sym->secondary_type = VOID; // Default sym->size = size; sym->ref = 0; if (type == PLEX || type == METHOD || type == TRAIT) { sym->args = new_list(arena); sym->fields = new_list(arena); } list_push(arena, parser.current_scope->symbols, sym, sizeof(Symbol)); return sym; } /**************************************************** * Parser ***************************************************/ bool parse_trait() { return true; } bool parse_plex() { return true; } bool parse_function() { return true; } bool parse_if() { return true; } bool parse_loop() { return true; } bool parse_while() { return true; } bool parse_for() { return true; } bool parse_return() { return true; } bool parse_assignment() { return true; } bool parse_expression() { return true; } bool parse_statement() { return true; } bool compile(char *source) { return true; }