From 73510cb48ffaf9007d8df5a4baafa705d8cca1b4 Mon Sep 17 00:00:00 2001 From: SinusFox Date: Mon, 15 May 2023 15:27:23 +0200 Subject: [PATCH] getNextCharacter --- Exercise 3/Lexer.c | 21 +++++++++++++++++++-- Exercise 3/Lexer.h | 1 + 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Exercise 3/Lexer.c b/Exercise 3/Lexer.c index eb341d1..2a04629 100644 --- a/Exercise 3/Lexer.c +++ b/Exercise 3/Lexer.c @@ -9,8 +9,11 @@ int start(char* src) { return _STOP_; // stopping the state machine in any other case } -int getNextCharacter(char* src) { - return _STOP_; // placeholder +int getNextCharacter(char* pos) { + if (isLetter(*pos)) { + return _READ_IDENTIFIER_; // continues to read the identifier + } + return _STOP_; // stopping the state machine in any other case } int readIdentifier(char* src) { @@ -28,3 +31,17 @@ int readOperator(char* src) { int readPunctuation(char* src) { return _STOP_; // placeholder } + +int isLetter(char in) { + if (in >= 'A') { // capital letters + if (in <= 'Z') { + return 1; + } + } + if (in >= 'a') { // non-capital letters + if (in <= 'z') { + return 1; + } + } + return 0; // returning 0 if it's no letter +} diff --git a/Exercise 3/Lexer.h b/Exercise 3/Lexer.h index 3e6fbe7..8a99a5f 100644 --- a/Exercise 3/Lexer.h +++ b/Exercise 3/Lexer.h @@ -24,3 +24,4 @@ int readNumLit(char*); int readOperator(char*); int readPunctuation(char*); int main(); +int isLetter(char);