From 942bbf33dcce413aadc7cc51693b184d6172c302 Mon Sep 17 00:00:00 2001 From: c+1 Date: Fri, 5 May 2023 16:37:57 -0400 Subject: HEKLP IT WON"T TERMINATc --- src/include/lexer.h | 2 ++ src/lexer.c | 30 +++++++++++++++--------------- src/main.c | 13 ++++++++++++- src/token.c | 0 src/tree.c | 0 5 files changed, 29 insertions(+), 16 deletions(-) mode change 100644 => 100755 src/lexer.c mode change 100644 => 100755 src/main.c mode change 100644 => 100755 src/token.c mode change 100644 => 100755 src/tree.c (limited to 'src') diff --git a/src/include/lexer.h b/src/include/lexer.h index e6bee55..a0e40af 100644 --- a/src/include/lexer.h +++ b/src/include/lexer.h @@ -17,6 +17,8 @@ token_t* lexer_get_next_token(lexer_t* lexer); token_t* lexer_get_string(lexer_t* lexer); +token_t* lexer_get_comment(lexer_t* lexer); + token_t* lexer_get_id(lexer_t* lexer); token_t* lexer_next_token(lexer_t* lexer, token_t* token); diff --git a/src/lexer.c b/src/lexer.c old mode 100644 new mode 100755 index 99ed54b..6e8c08d --- a/src/lexer.c +++ b/src/lexer.c @@ -69,20 +69,8 @@ token_t* lexer_get_next_token(lexer_t* lexer) { lexer_get_c_as_string(lexer) ) ); break; - case '[': return lexer_next_token( - lexer, - token_init( - TOKEN_LBRAK, - lexer_get_c_as_string(lexer) - ) - ); break; - case ']': return lexer_next_token( - lexer, - token_init( - TOKEN_RBRAK, - lexer_get_c_as_string(lexer) - ) - ); break; + case '[': return lexer_get_comment(lexer); break; + case ']': lexer_next(lexer); break; case '#': return lexer_next_token( lexer, token_init( @@ -100,7 +88,8 @@ token_t* lexer_get_next_token(lexer_t* lexer) { } } - return token_init(TOKEN_EOF, "\0"); + // return token_init(TOKEN_EOF, "\0"); + return NULL; } token_t* lexer_get_string(lexer_t* lexer) { @@ -121,6 +110,17 @@ token_t* lexer_get_string(lexer_t* lexer) { return token_init(TOKEN_QUOTE, str_so_far); } +token_t* lexer_get_comment(lexer_t* lexer) { + lexer_next(lexer); + + while (lexer->c != ']') { + lexer_next(lexer); + } + + lexer_next(lexer); + return token_init(TOKEN_SEMI, NULL); +} + token_t* lexer_get_id(lexer_t* lexer) { char* str_so_far = calloc(1, sizeof(char)); str_so_far[0] = '\0'; diff --git a/src/main.c b/src/main.c old mode 100644 new mode 100755 index a9682a6..45ee0c6 --- a/src/main.c +++ b/src/main.c @@ -1,7 +1,18 @@ #include +#include "include/lexer.h" int main(int argc, char* argv[]) { - printf("Hello, world."); + lexer_t* lexer = lexer_init( + "[nice & simple]\nlet it = \"Hello, World!\";\nsay it;\n" + ); + + printf("\n=== INPUT =======\n%s\n=== END INPUT ===\n", lexer->content); + + token_t* token = NULL; + + while ((token = lexer_get_next_token(lexer)) != NULL) { + printf("===\ntoken type: %d\ntoken value: %s\n===\n", token->type, token->value); + } return 0; } diff --git a/src/token.c b/src/token.c old mode 100644 new mode 100755 diff --git a/src/tree.c b/src/tree.c old mode 100644 new mode 100755 -- cgit v1.2.3