-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
71 lines (65 loc) · 1.25 KB
/
main.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// in mian.c
typedef enum{
key_input = 0;
key_print,
key_for,
key_next,
key_while,
key_wend,
key_if,
key_else,
key_endif,
key_goto,
key_let
} keywords;
keywords yacc(const STRING line){
if(!strnicmp(line,"INPUT ",6)){
return key_input;
}else if(!strnicmp(line,"PRINT ",6)){
return key_print;
}else if(!strnicmp(line,"FOR ",4)){
return key_for;
}else if(!strnicmp(line,"NEXT")){
return key_next
}else if(!strnicmp(line,"WHILE ", 6)){
return key_while;
}else if(!strnicmp(line,"WEND")){
return key_wend;
}else if(!strnicmp(line,"IF " ,3)){
return key_id;
}else if(!strnicmp(line,"ELSE")){
return key_else;
}else if(!strnicmp(line,"END IF")){
return key_endif;
}else if(!strnicmp(line,"GOTO ",5)){
return key_goto;
}else if(!strnicmp(line,"LET ",4)){
return key_let;
}
return -1;
}
void (*key_func[])(cosnt STRING) = {
exec_input,
exec_print,
exec_for,
exec_nextl,
exec_while,
exec_wend,
exec_if,
exec_else,
exec_endif,
exec_goto,
exec_assignment
};
int main(int argc, char *argv[]){
if(argc != 2){
fprintf(stderr, "usage: %s basic_script_file/n", argv[0]);
exit(EXIT_FAILURE);
}
load_program(argv[1]);
while(cp<code_size){
(*key_func[yacc(code[cp].line)])(code[cp].line);
cp++;
}
return EXIT_SUCCESS;
}