Skip to content

Commit 4e270f2

Browse files
authored
Update TokenStream.java
necessary changes after test failed. the commit also failed, unsure why...
1 parent dc523d2 commit 4e270f2

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/main/java/com/scanner/project/TokenStream.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
package com.scanner.project;
2+
23
// TokenStream.java
34

45
// Implementation of the Scanner for KAY
@@ -87,10 +88,13 @@ public Token nextToken() { // Main function of the scanner
8788
if (nextChar == '=') {
8889
t.setValue(t.getValue() + nextChar);
8990
nextChar = readChar();
91+
} else {
92+
// Single '=' is not a valid operator in KAY, mark as Other
93+
t.setType("Other");
9094
}
9195
return t;
9296
case '!':
93-
// !=
97+
// != or just !
9498
nextChar = readChar();
9599
if (nextChar == '=') {
96100
t.setValue(t.getValue() + nextChar);
@@ -138,7 +142,7 @@ public Token nextToken() { // Main function of the scanner
138142
}
139143
}
140144

141-
// Then check for a separator
145+
// Then check for a separator (including comma)
142146
if (isSeparator(nextChar)) {
143147
t.setType("Separator");
144148
t.setValue(t.getValue() + nextChar);
@@ -241,8 +245,8 @@ private void skipWhiteSpace() {
241245
}
242246

243247
private boolean isSeparator(char c) {
244-
// Separators in KAY: { } ; ( )
245-
return (c == '{' || c == '}' || c == ';' || c == '(' || c == ')');
248+
// Separators in KAY: { } ; ( ) ,
249+
return (c == '{' || c == '}' || c == ';' || c == '(' || c == ')' || c == ',');
246250
}
247251

248252
private boolean isOperator(char c) {
@@ -264,10 +268,4 @@ private boolean isDigit(char c) {
264268
public boolean isEndofFile() {
265269
return isEof;
266270
}
267-
}
268-
269-
public boolean isEndofFile() {
270-
return isEof;
271-
}
272-
273271
}

0 commit comments

Comments
 (0)