-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
112 lines (104 loc) · 2.19 KB
/
main.cpp
File metadata and controls
112 lines (104 loc) · 2.19 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <stdio.h>
#include "basic_io.h"
#include <string.h>
#include <stdlib.h>
#include "basic_io.h"
#include "grammar.h"
#define _CRT_SECURE_NO_WARNINGS
VARIANT memory[MEMORY_SIZE];
CODE code[PROGRAM_SIZE];
typedef enum
{
key_input = 0, // INPUT
key_print, // PRINT
key_for, // FOR .. TO .. STEP
key_next, // NEXT
key_while, // WHILE
key_wend, // WEND
key_if, // IF
key_else, // ELSE
key_endif, // END IF
key_goto, // GOTO
key_let // 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 (!stricmp(line, "NEXT"))
{
return key_next;
}
else if (!strnicmp(line, "WHILE ", 6))
{
return key_while;
}
else if (!stricmp(line, "WEND"))
{
return key_wend;
}
else if (!strnicmp(line, "IF ", 3))
{
return key_if;
}
else if (!stricmp(line, "ELSE"))
{
return key_else;
}
else if (!stricmp(line, "END IF"))
{
return key_endif;
}
else if (!strnicmp(line, "GOTO ", 5))
{
return key_goto;
}
else if (!strnicmp(line, "LET ", 4))
{
return key_let;
}
else if (strchr(line, '='))
{
return key_let;
}
return key_let;//要再加一个类型
}
void (*key_func[])(const STRING) = {
exec_input,
exec_print,
exec_for,
exec_next,
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);
}*/
STRING name = "test.txt";
load_program(name);
while (cp < code_size)
{
(*key_func[yacc(code[cp].line)]) (code[cp].line);
cp++;
}
return EXIT_SUCCESS;
}