29 lines
762 B
C
29 lines
762 B
C
#ifndef PARSER_H
|
|
#define PARSER_H
|
|
|
|
#include <stddef.h> // for size_t
|
|
|
|
// Forward declare
|
|
typedef struct ExprNode ExprNode;
|
|
|
|
// Node type: atom or list
|
|
struct ExprNode {
|
|
char *token; // For atoms: the value ("123", "$0", "add")
|
|
// For lists: the operator (first token)
|
|
ExprNode **children; // Array of child nodes (NULL if atom)
|
|
size_t child_count; // 0 if atom
|
|
int line; // Source line number (for errors)
|
|
};
|
|
|
|
// Parse a string into an Expr AST
|
|
ExprNode *expr_parse(const char *source, size_t source_len);
|
|
|
|
// Free an Expr AST (and all children)
|
|
void expr_free(ExprNode *node);
|
|
|
|
// Debug: print AST (for dev)
|
|
void expr_print(ExprNode *node, int indent);
|
|
|
|
void *safe_malloc(size_t size);
|
|
|
|
#endif |