diff options
author | c+1 | 2023-05-03 10:23:35 -0400 |
---|---|---|
committer | c+1 | 2023-05-03 10:23:35 -0400 |
commit | 9d981a2597dca067572ee16d1a3f6e99f9c6ddd6 (patch) | |
tree | 37de867b64491259e2b1dd33330bc234fd0b6eb1 /src | |
parent | 191c063e6c7332a8558835ce0d4710c3f8ba7de8 (diff) |
in which i learn how c structs work
Diffstat (limited to 'src')
-rw-r--r-- | src/.DS_Store | bin | 0 -> 6148 bytes | |||
-rw-r--r-- | src/include/lexer.h | 20 | ||||
-rw-r--r-- | src/include/main.h | 0 | ||||
-rw-r--r-- | src/lexer.c | 52 |
4 files changed, 72 insertions, 0 deletions
diff --git a/src/.DS_Store b/src/.DS_Store Binary files differnew file mode 100644 index 0000000..3246446 --- /dev/null +++ b/src/.DS_Store diff --git a/src/include/lexer.h b/src/include/lexer.h index e69de29..a20bf8c 100644 --- a/src/include/lexer.h +++ b/src/include/lexer.h @@ -0,0 +1,20 @@ +#ifndef LEXER_H +#define LEXER_H +#include "token.h" + +typedef struct LEXER_STRUC { + char c; // current character in content + unsigned int i; // index of c + char* content; // the code itself +} lexer_T; + +lexer_T* lexer_init(char* content); +void lexer_next(lexer_T* lexer); +void lexer_pass(lexer_T* lexer); +token_T* lexer_get_next_token(lexer_T* lexer); +token_T* lexer_get_string(lexer_T* lexer); +token_T* lexer_get_id(lexer_T* lexer); +token_T* lexer_next_token(lexer_T* lexer, token_T* token); +char* lexer_get_c_as_string(lexer_T* lexer); + +#endif diff --git a/src/include/main.h b/src/include/main.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/include/main.h diff --git a/src/lexer.c b/src/lexer.c new file mode 100644 index 0000000..692a9c9 --- /dev/null +++ b/src/lexer.c @@ -0,0 +1,52 @@ +#include "include/lexer.h" +#include <stdlib.h> +#include <string.h> + +lexer_T* lexer_init(char* content) { + lexer_T* lexer = calloc(1, sizeof(struct LEXER_STRUC)); + + lexer->content = content; + lexer->i = 0; + lexer->c = content[lexer->i]; + + return lexer; +} + +void lexer_next(lexer_T* lexer) { + // if not at end of line or file + if (lexer->c != '\0' && lexer->i < strlen(lexer->content)) { + lexer->i += 1; // advance index 1 character + lexer->c = lexer->content[lexer->i]; // set character w/ index + } +} + +void lexer_pass(lexer_T* lexer) { + while (lexer->c == ' ' || + lexer->c == '\t' || + lexer->c == '\n') { + lexer_next(lexer); + } +} + +token_T* lexer_get_next_token(lexer_T* lexer) { + while (lexer->c != '\0' && lexer->i < strlen(lexer->content)) { + if (lexer->c == ' ' || + lexer->c == '\t' || + lexer->c == '\n') { + + } + } +} + +token_T* lexer_get_string(lexer_T* lexer) { + +} +token_T* lexer_get_id(lexer_T* lexer) { + +} +token_T* lexer_next_token(lexer_T* lexer, token_T* token) { + +} +char* lexer_get_c_as_string(lexer_T* lexer) { + +} |