summaryrefslogtreecommitdiff
path: root/igen/lexer.h
blob: 0c5fea4a68731f7444d2da572c4f16e3054d51f2 (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
#ifndef LEXER_H
#define LEXER_H

#include <stdlib.h>
#include "preprocessor.h"

typedef enum stmt_type stmt_type;
typedef enum cond_type cond_type;
typedef struct source source;
typedef struct alt_stmt alt_stmt;
typedef struct cond_stmt cond_stmt;
typedef struct stmt stmt;

enum stmt_type {
	STMT_NONE,
	STMT_FUNC,
	STMT_EXPR,
	STMT_COND,
	STMT_COMP,
	NUM_STMTS
};

enum cond_type {
	COND_NONE,
	COND_IF,
	COND_FOR,
	COND_WHILE,
	COND_DO,
	NUM_CONDS
};

struct alt_stmt {
	int type;
	size_t offset;
	void *(*lex)(source *src, int dbg);
};

struct cond_stmt {
	cond_type type;
	expr *expr;
	stmt *stmt;
};

struct stmt {
	stmt_type type;
	union {
		func *func;
		expr *expr;
		cond_stmt *cond_stmt;
		stmt *down;
	};
	stmt *next;
};

extern int lex(source *src, int dbg);
#endif