forked from biblelamp/JavaExercises
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJBasic.java
More file actions
78 lines (74 loc) · 2.3 KB
/
Copy pathJBasic.java
File metadata and controls
78 lines (74 loc) · 2.3 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
/**
* JBasic - the simplest BASIC on Java
*
* @author Sergey Iryupin
* @version 0.3.6 dated Apr 09, 2018
*/
import java.util.Scanner;
import static tools.IConstants.*;
import tools.Tools;
import core.Interpreter;
import model.ProgramLines;
import model.Variables;
import model.Data;
import model.Def;
import model.Dim;
public class JBasic {
Interpreter interpreter;
ProgramLines programLines;
Variables variables;
Data data;
Def def;
Dim dim;
public static void main(String[] args) {
new JBasic();
}
public JBasic() {
programLines = new ProgramLines();
variables = new Variables();
dim = new Dim(variables);
def = new Def(variables);
data = new Data(variables, dim);
interpreter = new Interpreter(programLines, variables, data, def, dim);
Scanner scr = new Scanner(System.in);
String str = "";
System.out.println(MSG_START);
do {
if (Tools.getLineNumber(str) == 0)
System.out.println(MSG_READY);
str = scr.nextLine().trim();
switch (Tools.getPartOfString(str)) {
case CMD_NEW:
programLines.deleteAll();
break;
case CMD_LIST:
programLines.list();
break;
case CMD_SAVE:
programLines.save(str);
break;
case CMD_LOAD:
programLines.load(str);
break;
case CMD_RUN:
if (str.indexOf(" ") > -1) // load & run
programLines.load(str);
interpreter.run();
break;
case CMD_EXIT:
break;
case OPER_PRINT:
interpreter.print(str);
break;
case OPER_INPUT:
interpreter.input(Tools.getPartOfString(str, 1));
break;
default:
if (Tools.getLineNumber(str) > 0) // add/delete program line
programLines.add(str);
else
System.out.println(ERR_ILLEGAL_COMMAND);
}
} while (!str.equals(CMD_EXIT));
}
}