-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse.d
63 lines (57 loc) · 1.54 KB
/
parse.d
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
import fio = std.file, std.stdio, std.string, std.exception, std.algorithm, std.conv;
int main(string[] args){
enforce(args.length> 1);
string content = fio.readText(args[1]);
string[] lines = content.splitLines();
writeln(lines.length);
string[string] functions;
string[] program = eatPreamble(lines);
string[string][][] tokenized;
while( program.length > 0){
writeln( program.length);
tokenize( program, tokenized);
}
return 0;
}
string[] eatPreamble(string[] program){
return program[4..$];
}
void tokenize(ref string[] program, string[string][][] tokenized){
string[] tmp;
tmp = program[0].split(" ");
program=program[1..$];
if ( tmp.length ==0){
return;
}
if(tmp[0] == "define"){
writeln("case 1");
string proto = join(tmp[1..$] , " ");
return parseFunction(proto, program, tokenized);
}
if (tmp[0] =="declare"){
writeln("case 2");
string proto = join(tmp[1..$] , " ");
return parseExternal(proto, program, tokenized);
}
else if ( tmp[0] == ";" && tmp[1] == "<label>" ){
writeln("case 3");
size_t label = to!size_t(tmp[2]);
return parseLabel( label, program, tokenized);
}
else
throw new Exception("");
}
void parseFunction(string proto , ref string[] program , string[string][][] tokenized){
while ( program[0].split(" ")[0] != "}" ){
writeln("heisann");
program = program[1..$];
}
program = program[1..$];
return;
}
void parseExternal(string proto , string[] program , string[string][][] tokenized){
return;
}
void parseLabel(size_t label, string[] program, string[string][][] tokenized){
return;
}