aboutsummaryrefslogtreecommitdiff
path: root/include/parse.h
blob: de30f39c5e8a1967d5b9ac483ba3a0673805b761 (plain) (blame)
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
#ifndef CERC_PARSE_H
#define CERC_PARSE_H
#include "expr.h"

struct ast_expr {
	struct disjunction_e dis;
};

struct ast_externfunc {
	const char *name;
	struct type ret;
	struct type params[];
};

struct ast_param {
	const char *name;
	struct type type;
};

struct ast_cmd { /* TODO */ };

struct ast_block {
	struct ast_cmd *cmds;
};

struct ast_func {
	bool pub, exported;
	const char *name;
	struct ast_block block;
	struct type ret;
	struct ast_param params[];
};

enum const_global {
	CST_TYPE,
	CST_BOOL,
	CST_NUMBER,
	CST_STRING,
};

struct ast_const_global {
	bool pub;
	const char *name;
	enum const_global kind;
	union {
		struct type *type;
		bool b;
		struct number num;
		const char *str;
	} value;
};

struct ast_import {
	struct path path;
	const char *name;
};

enum toplevel {
	TOP_EXTERNFUNC,
	TOP_FUNC,
	TOP_CONST,
};

struct ast_toplevel {
	enum toplevel kind;
	union {
		struct ast_externfunc *extfn;
		struct ast_func *function;
		struct ast_const_global *constant;
	} decl;
};

struct ast_unit {
	struct ast_import *imports;
	struct ast_toplevel *tops;
	int impsz, implen;
	int topsz, toplen;
};

void parse(struct lexer *lexer, struct ast_unit *ast);

#endif