-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile.c
47 lines (37 loc) · 1.03 KB
/
compile.c
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
#include "compile.h"
#include "getSource.h"
#ifndef TBL
#define TBL
#include "table.h"
#endif
#define FIRSTADDR 2 /* 各ブロックの最初の変数アドレス */
static Token token; /* 次のトークンの保存用 */
int compile() {
printf("コンパイル開始\n");
initSource(); /* getSourceの初期化 */
token = nextToken(); /* 最初のトークン */
/* ブロックの初期化(これ以降の宣言は新しいブロックのもの)*/
blockBegin(FIRSTADDR);
block(0); /* 0はダミー(メインブロックの関数名は無い)*/
return 1;
}
void block(int pIndex) {
/* 宣言部のコンパイルを繰り返す */
while (1) {
switch (token.kind) {
case Const:
token = nextToken();
continue;
case Var:
token = nextToken();
continue;
case Func:
token = nextToken();
continue;
default: /* それ以外なら宣言部は終わり */
break;
}
break;
}
printf("==== コンパイル処理完了 ====\n");
}