-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10cc.h
77 lines (65 loc) · 1.29 KB
/
10cc.h
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
#define _GNU_SOURCE
#include <ctype.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// parse.c
typedef struct LVar LVar;
struct LVar {
LVar *next;
char *name;
int len;
int offset;
};
extern LVar *locals;
typedef enum {
ND_ADD, // +
ND_SUB, // -
ND_MUL, // *
ND_DIV, // /
ND_NUM, // integer
ND_EQ,
ND_NE,
ND_LT,
ND_LE,
ND_ASSIGN, // =
ND_LVAR, // local variable
ND_RETURN, // return
} NodeKind;
typedef struct Node Node;
struct Node {
NodeKind kind;
Node *lhs;
Node *rhs;
int val;
LVar *var;
};
Node *expr();
void program();
extern Node *code[100];
// token.c
typedef enum {
TK_RESERVED, // 記号
TK_IDENT, // 識別子
TK_NUM, // 整数トークン
TK_EOF, // 入力の終わりを表すトークン
TK_RETURN, // return
TK_IF, // if
TK_ELSE // else
} TokenKind;
typedef struct Token Token;
struct Token {
int kind; // トークンの型
Token *next; // 次の入力トークン
int val; // kindがTK_NUMの場合、その数値
char *str; // トークン文字列
int len; // トークンの長さ
};
Token *tokenize(char *p);
void error_at(char *loc, char *fmt, ...);
// codegen.c
void gen(Node *node);
// util.c
void error(char *fmt, ...);