-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTODO
More file actions
255 lines (173 loc) · 7.04 KB
/
TODO
File metadata and controls
255 lines (173 loc) · 7.04 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
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/Users/johnmetz/Desktop/cosc455/455JAVA/project2/Examples/under.txt
RETURN TRUE:---------------------------------------------------------------------------------------------------------
ab.txt
ab1.txt
(DONE)
if2.txt
(DONE)
euclid.txt
(DONE)
ab2.txt
(DONE)
print.txt
(DONE)
if.txt
(DONE)
hiding.txt
(DONE)
comment.txt - should end analysis immediately with success. No tokens should be returned.
(DONE)
ok.txt - contains all of the provided lexically-valid files combined. Should output 406 tokens of the various types.
(DONE)
RETURN FALSE:---------------------------------------------------------------------------------------------------------
ab1.txt - There is a missing end at the end of the input.
(DONE)
ok.txt - contains all of the provided lexically-valid files combined. Should output 406 tokens of the various types.
(DONE)
ab3 - In line 5 there is a space between : and =.
(DONE)
bad-syntax-2.txt - error in intt b.
(DONE)
euclid-error.txt - There is an error in !== inside the while loop.
(DONE)
hiding-error.txt - missing ) in the condition of the while loop.
(DONE)
nonsense - *** is an error.
(DONE)
empty.txt - same as comment.txt in regard to how the analyzer should react as the input file immediately starts with the end of the file.
(DONE)
under.txt - should report a lexical error, as no type of token can start with a character of an underscore.
(DONE)
exclame.txt - should report a lexical error for the first character.
(DONE)
ab2-error.txt - There should not be a ; before end.
(DONE)
bad-syntax-1.txt - Bad symbol 'IDENTIFIER': expected ;
(DONE)
euclid-synlexerror.txt
(DONE)
euclid-lexsynerror.txt
(DONE)
NEED WORK: ---------------------------------------------------------------------------------------------------------
test2.txt
ab3.txt
if3.txt
//todo 3. proper rules of else
//TODO THE AST TREE
while(lexeme2.contains("program"){
while (sc2.hasNextLine()) {
Scanner txt2 = new Scanner(text2);
while (txt2.hasNext()) {
if(lexeme2.contains("//"){
text2=sc2.nextLine();
}
else if(lexeme2.contains("program"){
break;
}
else if(!txt2.hasNext(){
System.out.print(" \nBAD TOKEN: " + lexeme);
System.out.print(" \nSYNTAX ERROR DETECTED, EXPECTED 'end'\n");
p.position(l, lexeme, text);
System.exit(0);
}
}
}
//THE CORE LOOP---------------------------------------------------------------------------------------------------------
while (sc2.hasNextLine()) {
Scanner txt2 = new Scanner(text2);
while (txt2.hasNext()) {
if (!txt.hasNext()) {
text2 = sc.nextLine();
System.out.print("|\n");
System.out.print("|\nNext Line: " + text + "\n\n");
}
}
//this checks the conditions end the last line
if (!sc.hasNextLine()) {
if (text.contains("end")) {
p.position(l, lexeme, text);
System.out.print("kind is keyword program: end");
v.value(lexeme, noError);
}
if(!text.matches("end")){
System.out.print(" \nBAD TOKEN: " + lexeme);
System.out.print(" \nSYNTAX ERROR DETECTED, EXPECTED 'end'?\n");
p.position(l, lexeme, text);
System.exit(0);
}
}
txt.close();
}
System.out.print("""
|
|
* Syntax Analyzer for COSC455
* by Wesley Lancaster
* Submitted on 11/22/22""");
sc.close();
} catch (FileNotFoundException e) {
System.out.println("Error: file was not found (exception e)");
}
}
}
while(!lexeme2.contains("program") || j <=10){
while (sc2.hasNextLine() && !lexeme2.contains("program")) {
Scanner txt2 = new Scanner(text2);
System.out.print("|\nNext Line: " + text2 + "\n");
while (text2.length() == 0) {text2 = sc2.nextLine();}
while (txt2.hasNext() && !lexeme2.contains("program")) {
lexeme2 = txt2.next();
System.out.println("lexeme: " + lexeme2);
if(lexeme2.contains("//")){
text2=sc2.nextLine();
System.out.println(j);
j++;
}
else if(lexeme2.contains("program")){
break;
}
if(!txt2.hasNext()){
System.out.print(" \nBAD TOKEN: " + lexeme2);
System.out.print(" \nSYNTAX ERROR DETECTED, EXPECTED 'program'\n");
p.position(l, lexeme2, text2);
System.exit(0);
}
}
}
}
sc2.close();
//this is to make sure a program starts with 'program'
Scanner sc2 = new Scanner(x);
String text2 = sc.nextLine();
String lexeme2 = "";
int j = 0;
while(sc2.hasNextLine()){
while (text2.length() == 0) {text2 = sc2.nextLine();}
Scanner txt2 = new Scanner(text2);
while(txt2.hasNext()){
lexeme2 = txt2.next();
System.out.print("|\nNext lexeme: " + text2 + "\n\n");
if(lexeme2.contains("//")){
while(txt2.hasNext()){
text2 = sc2.nextLine();
System.out.print("|\n");
System.out.print("|\nNext Line: " + text2 + "\n\n");
}
}
else if(lexeme2.contains("program")){
break;
}
if (!txt2.hasNext()) { //if no more lexemes, read to next line
text2 = sc2.nextLine();
System.out.print("|\n");
System.out.print("|\nNext Line: " + text2 + "\n\n");
}
}
if(!sc2.hasNextLine()){
System.out.print(" \nBAD TOKEN: " + lexeme2);
System.out.print(" \nSYNTAX ERROR DETECTED, EXPECTED 'program'\n");
p.position(l, lexeme2, text2);
System.exit(0);
}
}
sc2.close();