#ifndef PARSER_H #define PARSER_H #include "ast.h" #include "limits.h" #include "scanner.h" /* Parsing context to handle ambiguities */ typedef enum { PARSE_CTX_NORMAL, /* Normal expression context */ PARSE_CTX_CONDITION, /* Inside condition where { starts block */ } parse_ctx_t; /* Parser state */ typedef struct parser_t { scanner_t scanner; token_t current; token_t previous; node_t *root; u32 errors; node_t nodes[MAX_NODES]; u32 nnodes; parse_ctx_t context; /* Pool for variable-length node pointer arrays. * Nodes store an index + count into this pool instead of * embedding large arrays, keeping node_t small. */ struct node_t *ptrs[MAX_NODEPTR_POOL]; u32 nptrs; } parser_t; /* Initialize parser with scanner */ void parser_init(parser_t *p); /* Parse a complete program */ node_t *parser_parse(parser_t *p); #endif