diff --git a/Exercise 3/TestLexer.c b/Exercise 3/TestLexer.c index 552b513..353ffc0 100644 --- a/Exercise 3/TestLexer.c +++ b/Exercise 3/TestLexer.c @@ -1,3 +1,5 @@ +/* This program is not finished! */ + #include #include "Lexer.h" #include "Lexer.c" diff --git a/Exercise 4/Lexer.c b/Exercise 4/Lexer.c new file mode 100644 index 0000000..ab79784 --- /dev/null +++ b/Exercise 4/Lexer.c @@ -0,0 +1,11 @@ +#include "Lexer.h" + +void init_Lexer(Lexer_t* lexptr, char* src_in){ + lexptr->state = _START_; + lexptr->source_code = src_in; + lexptr->current_pos = &src_in; +} + +void run_Lexer(Lexer_t* lexer) { + +} diff --git a/Exercise 4/Lexer.h b/Exercise 4/Lexer.h new file mode 100644 index 0000000..004ba8f --- /dev/null +++ b/Exercise 4/Lexer.h @@ -0,0 +1,31 @@ +/* symbols */ +#define _LETTER_ 1 +#define _DIGIT_ 2 +#define _OPERATOR_ 3 +#define _PUNCTUATION_ 4 +#define _END_OF_LINE_ 5 +#define _UNKNOWN_ 10 + +/* state */ +#define _START_ 100 +#define _GET_NEXT_CHARACTER_ 110 +#define _READ_IDENTIFIER_ 120 +#define _READ_NUM_LIT_ 130 +#define _READ_OPERATOR_ 140 +#define _READ_PUNCTUATION_ 150 +#define _STOP_ 999 +#define _ERROR_ 1000 + +// lexer struct +struct Lexer_s { + int state; + char* source_code; + char** current_pos; + }; + +// typedef +typedef struct Lexer_s Lexer_t; + +// methods +void init_Lexer(Lexer_t*, char*); +void run_Lexer(Lexer_t*); diff --git a/Exercise 4/TestLexer.c b/Exercise 4/TestLexer.c new file mode 100644 index 0000000..1103e9e --- /dev/null +++ b/Exercise 4/TestLexer.c @@ -0,0 +1,15 @@ +#include +#include "Lexer.h" + +int main() { + // creating a variable of type Lexer_s + struct Lexer_s this_Lexer; // declaring this_Lexer, not initialization -> random values + + // initializing the lexer with proper values + init_Lexer(&this_Lexer, "index = 2 * count + 42;"); + + // starting the lexer + run_Lexer(&this_Lexer); + + return 0; +}