Skip to content

Commit dcf4acc

Browse files
committed
Keywords
1 parent 24fa13e commit dcf4acc

File tree

3 files changed

+78
-50
lines changed

3 files changed

+78
-50
lines changed

ecr/domain/core/core-keywords.h

Lines changed: 76 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,81 @@
11
#ifndef CORE_KEYWORDS_H
22
#define CORE_KEYWORDS_H
33

4-
char* keywords[] = {
5-
"add",
6-
"append",
7-
"array",
8-
"begin",
9-
"clear",
10-
"close",
11-
"debug",
12-
"decrement",
13-
"delete",
14-
"divide",
15-
"dummy",
16-
"end",
17-
"exit",
18-
"file",
19-
"fork",
20-
"get",
21-
"gosub",
22-
"go",
23-
"goto",
24-
"gotoPC",
25-
"if",
26-
"increment",
27-
"index",
28-
"input",
29-
"init",
30-
"multiply",
31-
"object",
32-
"open",
33-
"pop",
34-
"post",
35-
"print",
36-
"push",
37-
"put",
38-
"read",
39-
"replace",
40-
"return",
41-
"script",
42-
"set",
43-
"split",
44-
"stack",
45-
"stop",
46-
"system",
47-
"take",
48-
"toggle",
49-
"variable",
50-
"wait",
51-
"while",
52-
"write"
4+
struct HashItem {
5+
const char* name;
6+
char* next;
537
};
548

55-
#endif
9+
class CoreKeywords {
10+
11+
private:
12+
13+
int size = 0;
14+
HashItem* table;
15+
16+
public:
17+
18+
void addKeyword(const char* keyword) {
19+
HashItem* item = &table[size];
20+
item->name = keyword;
21+
item->next = NULL;
22+
size++;
23+
};
24+
25+
CoreKeywords() {
26+
table = (HashItem*)malloc(sizeof(HashItem) * 100);
27+
addKeyword("add");
28+
addKeyword("append");
29+
addKeyword("array");
30+
addKeyword("begin");
31+
addKeyword("clear");
32+
addKeyword("close");
33+
addKeyword("decrement");
34+
addKeyword("delete");
35+
addKeyword("divide");
36+
addKeyword("dummy");
37+
addKeyword("end");
38+
addKeyword("exit");
39+
addKeyword("file");
40+
addKeyword("fork");
41+
addKeyword("get");
42+
addKeyword("gosub");
43+
addKeyword("go");
44+
addKeyword("goto");
45+
addKeyword("gotoPC");
46+
addKeyword("if");
47+
addKeyword("increment");
48+
addKeyword("index");
49+
addKeyword("init");
50+
addKeyword("multiply");
51+
addKeyword("object");
52+
addKeyword("open");
53+
addKeyword("pop");
54+
addKeyword("post");
55+
addKeyword("print");
56+
addKeyword("push");
57+
addKeyword("put");
58+
addKeyword("read");
59+
addKeyword("replace");
60+
addKeyword("return");
61+
addKeyword("script");
62+
addKeyword("set");
63+
addKeyword("split");
64+
addKeyword("stack");
65+
addKeyword("stop");
66+
addKeyword("system");
67+
addKeyword("take");
68+
addKeyword("take");
69+
addKeyword("variable");
70+
addKeyword("wait");
71+
addKeyword("while");
72+
addKeyword("write");
73+
74+
for (int n = 0; n < size; n++) {
75+
printf("%s\n", table[n].name);
76+
}
77+
};
78+
79+
};
80+
81+
#endif

ecr/ecr

-24.7 KB
Binary file not shown.

ecr/run.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define RUN_H
33

44
#include "ecr.h"
5+
#include "domain/core/core-keywords.h"
56

67
char* command = (char*)malloc(1);
78

@@ -16,6 +17,7 @@ int runOneCommand(char* cmd, StringArray* keys){
1617

1718
int run(StringArray* codes, StringArray* keys) {
1819
printf("Run the program\n");
20+
CoreKeywords core;
1921
char* command = codes->array[0];
2022
runOneCommand(command, keys);
2123
return 0;

0 commit comments

Comments
 (0)