Skip to content

Commit b4a897e

Browse files
Merge pull request #27 from Pip-Install-Party/jacobs999-develop
Jacobs999 develop
2 parents eccaf2e + 62d3aab commit b4a897e

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

tokenizer.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ void Tokenizer::state0(std::istringstream &inputStream, int &lineCount, std::ost
103103
} else if (ch == '\'') { // Handle single quotes (character literals).
104104
buffer << "\nToken type: SINGLE_QUOTE\n";
105105
buffer << "Token: " << ch << "\n";
106+
//state1(inputStream, lineCount, buffer);
106107
state5(inputStream, lineCount, buffer); // Transition to state5 for single quotes.
107108
return state0(inputStream, lineCount, buffer);
108109
} else if (ch == '_') { // Handle underscores.
@@ -136,13 +137,9 @@ void Tokenizer::state1(std::istringstream &inputStream, int &lineCount, std::ost
136137
std::cerr << "Error: Unterminated string\n";
137138
exit(1);
138139
} else if (ch == '"') { // End of the string literal.
139-
buffer << "\n";
140-
buffer << "\nToken type: DOUBLE_QUOTE\n";
140+
buffer << "\n\nToken type: DOUBLE_QUOTE\n";
141141
buffer << "Token: " << ch << "\n";
142142
return;
143-
} else if (ch == '\\') { // Handle escape characters inside the string.
144-
buffer << ch; // Add the backslash to the buffer.
145-
state9(inputStream, lineCount, buffer); // Transition to state9 to handle the escape sequence.
146143
} else if (ch == '\n') { // Handle newlines within the string (error).
147144
lineCount++;
148145
std::cerr << "Error: Unterminated string on line " << lineCount << "\n";
@@ -209,7 +206,7 @@ void Tokenizer::state4(std::istringstream &inputStream, int &lineCount, std::ost
209206
return state4(inputStream, lineCount, buffer); // Continue processing the identifier.
210207
}
211208

212-
// Handle character literals enclosed by single quotes.
209+
// Handle characters enclosed by single quotes.
213210
void Tokenizer::state5(std::istringstream &inputStream, int &lineCount, std::ostringstream& buffer) {
214211
char ch;
215212
inputStream.get(ch); // Get the next character.
@@ -222,9 +219,11 @@ void Tokenizer::state5(std::istringstream &inputStream, int &lineCount, std::ost
222219
buffer << "Token: ''\n"; // Empty literal.
223220
return;
224221
} else if (ch == '\\') { // Escape character inside the literal.
225-
state8(inputStream, lineCount, buffer); // Handle escape sequences.
226-
} else { // Handle regular character literals.
227-
buffer << "\nToken type: STRING\n";
222+
buffer << "\nToken type: CHARACTER\n";
223+
inputStream.get(ch); // Found backslash so need to get escaped character as well
224+
buffer << "Token: \\" << ch << "\n"; // Add escape sequence to buffer.
225+
} else { // Handle regular single length character literals.
226+
buffer << "\nToken type: CHARACTER\n";
228227
buffer << "Token: " << ch << "\n";
229228
}
230229
state11(inputStream, lineCount, buffer); // Check for the closing single quote.
@@ -263,7 +262,7 @@ void Tokenizer::state7(std::istringstream &inputStream, int &lineCount, std::ost
263262
return;
264263
}
265264

266-
// Handle escape sequences inside string literals (e.g., '\n', '\t').
265+
// Handle escape sequences inside string literals (e.g., '\n', '\t') and character literals
267266
void Tokenizer::state8(std::istringstream &inputStream, int &lineCount, std::ostringstream& buffer) {
268267
char ch;
269268
inputStream.get(ch); // Get the character after the backslash.
@@ -281,7 +280,7 @@ void Tokenizer::state8(std::istringstream &inputStream, int &lineCount, std::ost
281280
}
282281

283282
// Handle character escape sequences (like '\n').
284-
void Tokenizer::state9(std::istringstream &inputStream, int &lineCount, std::ostringstream& buffer) {
283+
/*void Tokenizer::state9(std::istringstream &inputStream, int &lineCount, std::ostringstream& buffer) {
285284
char ch;
286285
inputStream.get(ch); // Get the character after the backslash.
287286
@@ -290,7 +289,7 @@ void Tokenizer::state9(std::istringstream &inputStream, int &lineCount, std::ost
290289
} else {
291290
buffer << ch; // Handle other escape characters.
292291
}
293-
}
292+
}*/
294293

295294
// Handle boolean AND (&&) and bitwise AND (&).
296295
void Tokenizer::state10(std::istringstream &inputStream, int &lineCount, std::ostringstream& buffer) {

0 commit comments

Comments
 (0)