-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
184 lines (164 loc) · 5.2 KB
/
main.cpp
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#include <string>
#include <vector>
#include <conio.h>
#include <cstdlib>
#include <iostream>
#include "lexScanner.h"
#include "expEvaluator.h"
#include "Interpreter.h"
using namespace std;
int main()
{
string buffer = " ";
string fileName;
vector <string> myLinesOfStatements;
Interpreter aProgram(myLinesOfStatements);
Interpreter bProgram(myLinesOfStatements);
Interpreter cProgram(myLinesOfStatements);
char z, x;
bool in = true; // while the user is using the program this var is set to true and the menu keeps looping.
// when the user wants to quit, it is set to false and the loop ends.
char keyPressed, keyPressed2; // This var stores which menu selection the user picks.
while (in)
{
cout << endl << endl << endl;
cout << "****************************************************" << endl;
cout << "** MENU:(press a character to select an option) **" << endl;
cout << "****************************************************" << endl;
cout << "Q. [QUIT] Quit." << endl;
cout << endl;
cout << "T. [TYPE A PRPGRAM] TYPE A PROGRAM TO TEST" << endl;
cout << endl;
cout << "A. [STANDARD TEST] TEST PROGRAM WITH STANDARD FILE" << endl;
cout << endl;
cout << "L. [LOAD A PROGRAM] READ A PROGRAM FROM FILE " << endl;
cout << endl;
cout << "****************************************************" << endl << endl;
cout << "Your choice is: ";
cin >> keyPressed;
switch (keyPressed) {
case 'Q': case 'q'://Quit
cout << "[QUIT]:" << endl;
in = false;
break;
case 'L': case 'l':
myLinesOfStatements.clear();
LexicalScanner::LoadProgram(myLinesOfStatements);
cout << endl << endl << "Executing Program..." << endl;
cProgram.executeProgram(myLinesOfStatements);
_getch();
cin.clear();
aProgram.clear();
break;
case 'T': case 't':
//Ask the user to type in another source program for analysis
buffer.clear();
cout << endl
<< "********************************************************************"
<< endl;
cout << endl << "Enter a program (as lines of statements), one line at a time,"
<< endl << "with a line of single . to signal the end of the program input."
<< endl;
myLinesOfStatements.clear();
while (buffer != ".")
{
getline(cin, buffer);
if (buffer.size() > 0 && buffer != ".")
myLinesOfStatements.push_back(buffer);
}
for (size_t i = 0; i < myLinesOfStatements.size(); i++)
{
cout << "Line["
<< i
<< "].\t"
<< myLinesOfStatements[i]
<< endl;
}
cout << endl << "Executing the program..." << endl << endl;
//Get the lexical information
cout << endl << endl << "Executing Program..." << endl;
bProgram.executeProgram(myLinesOfStatements);
_getch();
cin.clear();
bProgram.clear();
break;
case 'A': case 'a':
myLinesOfStatements.clear();
cout << endl << endl << endl;
cout << "****************************************************" << endl;
cout << "************* STANDRD TEST OPTION ****************" << endl;
cout << "****************************************************" << endl;
cout << "1 - Standard Test 1" << endl;
cout << endl;
cout << "2 - Standard Test 2" << endl;
cout << endl;
cout << "3 - Standard Test 3" << endl;
cout << endl;
cout << "4 - Standard Test 4" << endl;
cout << endl;
cout << "5 - Standard Test 5 Programming 4B" << endl;
cout << endl;
cout << "6 - Standard Test 6 Programming 4B" << endl;
cout << endl;
cout << "****************************************************" << endl << endl;
cin >> keyPressed2;
switch (keyPressed2) {
case '1':
fileName = "1.txt";
LexicalScanner::LoadProgram(myLinesOfStatements, (fileName));
cout << endl << endl << "Executing Program..." << endl;
cProgram.executeProgram(myLinesOfStatements);
_getch();
cin.clear();
cProgram.clear();
break;
case '2':
fileName = { "2.txt" };
LexicalScanner::LoadProgram(myLinesOfStatements, (fileName));
cout << endl << endl << "Executing Program..." << endl;
cProgram.executeProgram(myLinesOfStatements);
_getch();
cin.clear();
cProgram.clear();
break;
case '3':
fileName = { "3.txt" };
LexicalScanner::LoadProgram(myLinesOfStatements, (fileName));
cout << endl << endl << "Executing Program..." << endl;
cProgram.executeProgram(myLinesOfStatements);
_getch();
cin.clear();
cProgram.clear();
break;
case '4':
fileName = { "4.txt" };
LexicalScanner::LoadProgram(myLinesOfStatements, (fileName));
cout << endl << endl << "Executing Program..." << endl;
cProgram.executeProgram(myLinesOfStatements);
_getch();
cin.clear();
cProgram.clear();
break;
case '5':
fileName = { "5.txt" };
LexicalScanner::LoadProgram(myLinesOfStatements, (fileName));
cout << endl << endl << "Executing Program..." << endl;
cProgram.executeProgram(myLinesOfStatements);
_getch();
cin.clear();
cProgram.clear();
break;
case '6':
fileName = { "6.txt" };
LexicalScanner::LoadProgram(myLinesOfStatements, (fileName));
cout << endl << endl << "Executing Program..." << endl;
cProgram.executeProgram(myLinesOfStatements);
_getch();
cin.clear();
cProgram.clear();
break;
}
}
}
return 0;
}