11package 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