From 9d981a2597dca067572ee16d1a3f6e99f9c6ddd6 Mon Sep 17 00:00:00 2001 From: c+1 Date: Wed, 3 May 2023 10:23:35 -0400 Subject: in which i learn how c structs work --- examples/hello.halk | 3 ++- src/.DS_Store | Bin 0 -> 6148 bytes src/include/lexer.h | 20 ++++++++++++++++++++ src/include/main.h | 0 src/lexer.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 src/.DS_Store create mode 100644 src/include/main.h create mode 100644 src/lexer.c diff --git a/examples/hello.halk b/examples/hello.halk index f36db0a..da10494 100644 --- a/examples/hello.halk +++ b/examples/hello.halk @@ -1,4 +1,5 @@ -USE.io; +USE."io"; message="Hello, World!"; + io~o.message; diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000..3246446 Binary files /dev/null and b/src/.DS_Store differ 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 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 +#include + +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) { + +} -- cgit v1.2.3