Exercise 2 + 3 #4

Merged
SinusFox merged 7 commits from exercise-2 into main 2023-05-15 12:36:20 +00:00
Showing only changes of commit 39f2ee4394 - Show all commits
+45 -5
View File
@@ -2,15 +2,37 @@
#include "Lexer.h" #include "Lexer.h"
int start(char* sourcecode) { int start(char* sourcecode) {
if (sourcecode != NULL) { // if (sourcecode != NULL) {
return _GET_NEXT_CHARACTER_; // return _GET_NEXT_CHARACTER_;
} else { // } else {
return _STOP_; // return _STOP_;
// }
return _STOP_; // placeholder
} }
int getNextCharacter() {
return _STOP_; // placeholder
}
int readIdentifier() {
return _STOP_; // placeholder
}
int readNumLit() {
return _STOP_; // placeholder
}
int readOperator() {
return _STOP_; // placeholder
}
int readPunctuation() {
return _STOP_; // placeholder
} }
int main() { int main() {
char* sourcecode = "Hello World the second - I coded this before. So yeah, FOXES ARE SUPERIOR.\nBut the professor wants us to write the following: \"index = 2 * count + 42;\""; char* sourcecode = "Hello World the second - I coded this before. So yeah, FOXES ARE SUPERIOR.\nBut the professor wants us to write the following: \"index = 2 * count + 42;\"\n\n";
printf(sourcecode); printf(sourcecode);
int lexer_state = _START_; int lexer_state = _START_;
@@ -19,9 +41,27 @@ int main() {
case _START_: case _START_:
lexer_state = start(sourcecode); lexer_state = start(sourcecode);
break; break;
case _GET_NEXT_CHARACTER_:
lexer_state = getNextCharacter();
break;
case _READ_IDENTIFIER_:
lexer_state = readIdentifier();
break;
case _READ_NUM_LIT_:
lexer_state = readNumLit();
break;
case _READ_OPERATOR_:
lexer_state = readOperator();
break;
case _READ_PUNCTUATION_:
lexer_state = readPunctuation();
break;
default: lexer_state = _ERROR_; default: lexer_state = _ERROR_;
} }
} while (lexer_state != _STOP_); } while (lexer_state != _STOP_);
printf("Lexer exited with code ");
// printf(lexer_state);
return 0; return 0;
} }