aboutsummaryrefslogtreecommitdiff
path: root/src/parser.c
blob: e61b1e5b8ae1e7928d276e1a506e19e829df57c5 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <stdlib.h>
#include <string.h>

struct text {
    char *str;
};

struct symbol {
    char *value;
};

struct expression {
    struct symbol symbol;
};

struct statement {

};

/* discard during parsing phase */
struct comment {};


enum node_type {
    NODE_EXPR,
    NODE_COMMENT,
    NODE_TEXT,
};

struct node {
    enum node_type type;
    union content {
        struct expression expr;
        struct comment comment;
        struct text text;
    } content;
};

struct ast {
    int size;
    int cap;
    struct node **nodes;
};

enum token_type {
    TOK_EOF,
    TOK_EXPR_OPEN,
    TOK_EXPR_CLOSE,
    TOK_COMMENT_OPEN,
    TOK_COMMENT_CLOSE,
    TOK_STMT_OPEN,
    TOK_STMT_CLOSE,
    TOK_MINUS,
    TOK_SYMBOL,
    TOK_TEXT,
};

struct token {
    enum token_type type;
    char *literal;
};

struct token gettoken(char *str) {
    struct token t;
    switch (str[0]) {
        case '{':

        break;

        case '}':

        break;

        case '\0': 
            t.type = TOK_EOF;
        break;
    }

    return t;
};

struct ast* parse(char *str) {
    struct ast* ast = malloc(sizeof *ast);
    ast->size = 0;
    ast->cap = 64;
    ast->nodes = malloc(ast->cap * sizeof *ast->nodes);

    for (struct token t = gettoken(str); t.type != TOK_EOF; t= gettoken(str)) {

    }

    return ast;
}