aboutsummaryrefslogtreecommitdiffstats
path: root/src/parser.h
blob: 6a4401e5c17bc8c2ef251557901f01c1a2a3c3a3 (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
#ifndef BDL_PARSER_H
#define BDL_PARSER_H

#include "lexer.h"

typedef struct Parser {
    Token *tokens;
    size_t current;
} Parser;

typedef enum NodeType {
    NODE_BUILTIN,
    NODE_NUMBER,
    NODE_BOOL,
    NODE_STRING,
    NODE_SYMBOL,
    NODE_DEF,
} NodeType;

typedef struct Node {
    NodeType type;

    union {
        // Numbers.
        struct {
            bool negative;
            size_t integral;
            size_t fractional;
        } number;

        // String/symbol.
        StringView string;

        // Boolean.
        bool boolean;

        // Builtin primitive.
        struct {
            TokenType type;
            struct Node **args;
        } builtin;

        // Variable definition.
        struct {
            struct Node *symbol;
            struct Node *value;
            // TODO: type information
        } def;
    };
} Node;

void parse(Token *tokens);
Node * parse_next(Parser *parser);

#endif // BDL_PARSER_H