-
Notifications
You must be signed in to change notification settings - Fork 1
/
dispatch.h
64 lines (54 loc) · 1.28 KB
/
dispatch.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
#include "parser.h"
#include "ast/ast_parse.h"
static void HandleFunction() {
if (ast_function *F = parse_function())
{
if (!F->Codegen())
{
fprintf(stderr, "Error reading function definition:");
}
} else {
// Skip token for error recovery.
parser::get()->get_next_token();
}
}
static void HandleExtern() {
if (ast_function_prototype *P = ParseExtern()) {
if (!P->Codegen()) {
fprintf(stderr, "Error reading extern");
}
} else {
// Skip token for error recovery.
parser::get()->get_next_token();
}
}
static void HandleTopLevelExpression() {
// Evaluate a top-level expression into an anonymous function.
if (ast_function *F = ParseTopLevelExpr()) {
if (!F->Codegen()) {
fprintf(stderr, "Error generating code for top level expr\n");
}
} else {
// Skip token for error recovery.
parser::get()->get_next_token();
}
}
/// top ::= definition | external | expression | ';'
static void MainLoop() {
while (1) {
switch ( parser::get()->get_current_token() )
{
case tok_function:
HandleFunction();
break;
case tok_extern:
HandleExtern();
break;
default:
HandleTopLevelExpression();
break;
case tok_eof:
return;
}
}
}