From 39f2ee43942748653089234af9438f8dd7b761d4 Mon Sep 17 00:00:00 2001 From: SinusFox Date: Tue, 9 May 2023 15:06:26 +0200 Subject: [PATCH] added more states --- Exercise 2/C/TestLexer.c | 52 +++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/Exercise 2/C/TestLexer.c b/Exercise 2/C/TestLexer.c index f90000e..26fef6f 100644 --- a/Exercise 2/C/TestLexer.c +++ b/Exercise 2/C/TestLexer.c @@ -2,15 +2,37 @@ #include "Lexer.h" int start(char* sourcecode) { - if (sourcecode != NULL) { - return _GET_NEXT_CHARACTER_; - } else { - return _STOP_; - } + // if (sourcecode != NULL) { + // return _GET_NEXT_CHARACTER_; + // } else { + // 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() { - 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); int lexer_state = _START_; @@ -19,9 +41,27 @@ int main() { case _START_: lexer_state = start(sourcecode); 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_; } } while (lexer_state != _STOP_); + printf("Lexer exited with code "); + // printf(lexer_state); + return 0; }