diff options
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) { + +} |