#ifndef PARSER_H #define PARSER_H #include "value.h" #include "lexer.h" typedef struct parser *parser_t; typedef struct ast ast_t; struct ast { enum ast_type { AST_SEXP, AST_VALUE, AST_TYPES // number of types } type; union { struct sexp { struct ast *children; size_t nchildren; struct sexp *prev; } sexp; value_t value; }; }; struct parser { struct sexp *cur_sexp; struct quote_node { struct sexp *cur_sexp; struct quote_node *prev; } *quote_head; value_t begin_symbol_value; value_t quote_symbol_value; }; // allocate a parser // returns a parser on success and NULL on fail parser_t parser_create(); // deallocate a parser void parser_destroy(parser_t parser); // reset to its default state without destroying it // returns 0 on success void parser_reset(parser_t parser); void ast_reset(ast_t *ast_root); // self explanatory void ast_print(ast_t *ast_root); // turn the given toklist into an ast // returns 0 on success, and < 0 on a fatal error int parser_parse_toklist(parser_t parser, toklist_t *tokens, ast_t *ast); #endif