blob: 9193ca120423c35b7fceb270f72a7c6005ba5dc6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
#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
|