aboutsummaryrefslogtreecommitdiff
path: root/src/ast.h
blob: bd2e6283d517dbe7c96cee68494642cd54a15ee7 (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
#ifndef AST_H
#define AST_H

#include "lexer.h"

typedef struct node_t *ast_t;
struct ast_node {
    enum {
        NODE_SEXP,
        NODE_SYMBOL,
        NODE_LITERAL,
    } type;

    union {
        struct sexp {
            struct ast_node **children;
            size_t nchildren;
        } sexp;

        char *symbol;

        union {
            enum {
                NODE_LITERAL_NUM,
                NODE_LITERAL_STR,
            } type;

            int number;
            char *string;
        } literal;
    };
};

ast_t ast_create();
void ast_destroy(ast_t ast);
int ast_parse_lexer(ast_t ast, lexer_t lex);

#endif