-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain-parser.c
More file actions
68 lines (56 loc) · 1.47 KB
/
Copy pathmain-parser.c
File metadata and controls
68 lines (56 loc) · 1.47 KB
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
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <stddef.h>
#include "fatarena.h"
#include "token.h"
#include "lib/map.h"
#include "lex.h"
#include "parser.h"
FatArena fttok = {0};
FatArena ftident = {0};
FatArena ftlit = {0};
FatArena ftimmed = {0};
FatArena fttmp = {0};
FatArena ftast = {0};
FatArena ftsym = {0};
int line = 0;
int
main(int argc, char *argv[])
{
(void) argc;
(void) argv;
POK(ftnew(&ftident, 1000000) != 0, "fail to create a FatArena");
ftalloc(&ftident, NKEYWORDS + 1);// burn significant int
POK(ftnew(&ftimmed, 1000000) != 0, "fail to create a FatArena");
ftalloc(&ftimmed, NKEYWORDS + 1);// burn significant int
POK(ftnew(&ftlit, 1000000) != 0, "fail to create a FatArena");
ftalloc(&ftlit, NKEYWORDS + 1);// burn significant int
POK(ftnew(&fttok, 1000000) != 0, "fail to create a FatArena");
int ntok = 0;
POK(ftnew(&fttmp, 1000000) != 0, "fail to create a FatArena");
POK(ftnew(&ftast, 1000000) != 0, "fail to create a FatArena");
ETok *tlst = (ETok*) ftptr(&fttok, 0);
Tok t;
do {
t = getnext();
ftalloc(&fttok, sizeof(Tok));
if (t.type != SPC && t.type != NEWLINE) {
tlst[ntok++] = t.type;
}
} while (t.type != EOI);
int i = 0;
int res = -1;
intptr stmt = -1;
int pub = 0;
while (tlst[i] != EOI) {
res = parse_toplevel(tlst + i, &stmt, &pub);
if (res < 0) {
fprintf(stderr, "Error when parsing toplevel stmt.\n");
return 1;
}
printstmt(stdout, stmt);
fprintf(stdout, "\n");
i += res;
}
}