diff options
author | c+1 | 2023-05-05 16:37:57 -0400 |
---|---|---|
committer | c+1 | 2023-05-05 16:37:57 -0400 |
commit | 942bbf33dcce413aadc7cc51693b184d6172c302 (patch) | |
tree | db115d23fec88938d2ac890f35c0843d70a67a90 | |
parent | 89b5586c1a12ac47c47e609dc31aac597473812f (diff) |
HEKLP IT WON"T TERMINATc
-rw-r--r-- | .gitignore | 1 | ||||
-rwxr-xr-x[-rw-r--r--] | Makefile | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | README.md | 0 | ||||
-rw-r--r-- | examples/hello.halk | 32 | ||||
-rw-r--r-- | src/include/lexer.h | 2 | ||||
-rwxr-xr-x[-rw-r--r--] | src/lexer.c | 30 | ||||
-rwxr-xr-x[-rw-r--r--] | src/main.c | 13 | ||||
-rwxr-xr-x[-rw-r--r--] | src/token.c | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | src/tree.c | 0 |
9 files changed, 33 insertions, 45 deletions
@@ -80,3 +80,4 @@ tags # macos woes .DS_Store +plan.md diff --git a/README.md b/README.md index d5e0381..d5e0381 100644..100755 --- a/README.md +++ b/README.md 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 index 99ed54b..6e8c08d 100644..100755 --- 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 index a9682a6..45ee0c6 100644..100755 --- a/src/main.c +++ b/src/main.c @@ -1,7 +1,18 @@ #include <stdio.h> +#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 index 3021a64..3021a64 100644..100755 --- a/src/token.c +++ b/src/token.c diff --git a/src/tree.c b/src/tree.c index ab3a962..ab3a962 100644..100755 --- a/src/tree.c +++ b/src/tree.c |