diff options
Diffstat (limited to 'src/parser.h')
-rw-r--r-- | src/parser.h | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/parser.h b/src/parser.h new file mode 100644 index 0000000..8fc5d6c --- /dev/null +++ b/src/parser.h @@ -0,0 +1,60 @@ +#ifndef PARSER_H +#define PARSER_H + +#include "value.h" +#include "lexer.h" + +typedef struct parser *parser_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 root; + 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 a parser to its default state without destroying it +// returns 0 on success +void parser_reset(parser_t parser); + +// self explanatory +void parser_print_ast(parser_t parser); + +// turn the given lexer (which has already has tokens) into an ast +// returns 0 on success, > 0 when more tokens are needed, +// and < 0 on a fatal error +int parser_parse_lexer(parser_t parser, lexer_t lexer); + +#endif |