climp

Dirty interpreter for the limp programming language in C

git clone https://git.8pit.net/climp.git

 1typedef enum {
 2	OP_PLUS,
 3	OP_MINUS,
 4	OP_MULTI,
 5	OP_DIVIDE,
 6} binop;
 7
 8typedef enum {
 9	EXP_LIT,
10	EXP_VAR,
11	EXP_BIN,
12} expr_t;
13
14typedef struct parser parser;
15
16struct parser {
17	int cur;
18	size_t max;
19	scanner *scr;
20	token **buf, *peektok;
21};
22
23typedef struct expr expr;
24
25struct expr {
26	expr_t type;
27	union {
28		struct {
29			int num;
30		} literal;
31		struct {
32			char *var;
33		} variable;
34		struct {
35			binop op;
36			expr *expr1, *expr2;
37		} operation;
38	} d;
39};
40
41typedef enum {
42	STMT_ERROR,
43	STMT_DEFINE,
44	STMT_ASSIGN,
45	STMT_READ,
46	STMT_WRITE,
47	STMT_COND,
48	STMT_LOOP,
49} stmt_t;
50
51typedef struct statement statement;
52
53struct statement {
54	stmt_t type;
55	union {
56		struct {
57			int line;
58			char *msg;
59		} error;
60		struct {
61			expr *exp;
62			char *var;
63		} define;
64		struct {
65			expr *exp;
66			char *var;
67		} assign;
68		struct {
69			char *var;
70		} read;
71		struct {
72			expr *exp;
73		} write;
74		struct {
75			expr *cond;
76			statement **brn1, **brn2;
77		} cond;
78		struct {
79			expr *cond;
80			statement **brn;
81		} loop;
82	} d;
83};
84
85parser *newpar(char *m);
86void freepar(parser *p);
87void freestmt(statement *s);
88void freestmts(statement **s);
89statement **parseprog(parser *p, statement *e);