aboutsummaryrefslogtreecommitdiff
path: root/src/as_parser.h
blob: f1d3b62bd7dc97d4e4d357ab32195fa82f6ce9fd (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
#ifndef FVM_AS_PARSER_H_
#define FVM_AS_PARSER_H_

#include "as_tokenizer.h"
#include "utils.h"

#include "as_op.h"

struct arg {
    int64_t ival;
    double fval;
};
typedef struct arg arg;

struct instr {
    enum op op;
    arg* arg;
    const char* tag_name;
    int lineno;
};
typedef struct instr instr;

struct label {
    const char* name;
};
typedef struct label label;

struct stmt {
    struct label * label;
    struct instr * instr;
};
typedef struct stmt stmt;

struct stmts {
    struct stmt ** stmts;
};
typedef struct stmts stmts;

struct prog {
    struct stmts * stmts;
};
typedef struct prog prog;

// result<prog>
result parse_prog(allocator* alct, token_stream* ts);

// result<stmt>
result parse_stmt(allocator* alct, token_stream* ts);

// result<stmts>
result parse_stmts(allocator* alct, token_stream* ts);

// result<instr>
result parse_instr(allocator* alct, token_stream* ts);

// result<label>
result parse_label(allocator* alct, token_stream* ts);

// result<enum op>
result parse_op(allocator* alct, token_stream* ts);

#endif