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 --- .gitignore | 1 + Makefile | 0 README.md | 0 examples/hello.halk | 32 +++----------------------------- src/include/lexer.h | 2 ++ src/lexer.c | 30 +++++++++++++++--------------- src/main.c | 13 ++++++++++++- src/token.c | 0 src/tree.c | 0 9 files changed, 33 insertions(+), 45 deletions(-) mode change 100644 => 100755 Makefile mode change 100644 => 100755 README.md 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 diff --git a/.gitignore b/.gitignore index e098804..880f356 100644 --- a/.gitignore +++ b/.gitignore @@ -80,3 +80,4 @@ tags # macos woes .DS_Store +plan.md diff --git a/Makefile b/Makefile old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/examples/hello.halk b/examples/hello.halk index 47c6979..8a441cc 100644 --- a/examples/hello.halk +++ b/examples/hello.halk @@ -1,29 +1,3 @@ -[comments are in square brackets] - -[begin list with /] -[end list with \] -[items in list separated by &] - -[lines terminated by ;] - -[arguments given as a list after the .] - -[USE brings a module into scope] -USE./"base"&"io"\; - -[all variables are mutable at all times] -message="Hello, World!"; - -[new functions defined with = followed by a list of procedures, which are called procedurally when called] -say.msg=/ - -[functions/variables in a module are accessed through a ~ (analogous to dot notation)] -msg=io~escape.msg& -io~o.msg -\; - -for_each./ build_list./5\ & - -say.message - -\ +[nice & simple] +let it = "Hello, World!"; +say it; 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