aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorc+12023-05-05 16:37:57 -0400
committerc+12023-05-05 16:37:57 -0400
commit942bbf33dcce413aadc7cc51693b184d6172c302 (patch)
treedb115d23fec88938d2ac890f35c0843d70a67a90 /src
parent89b5586c1a12ac47c47e609dc31aac597473812f (diff)
HEKLP IT WON"T TERMINATc
Diffstat (limited to 'src')
-rw-r--r--src/include/lexer.h2
-rwxr-xr-x[-rw-r--r--]src/lexer.c30
-rwxr-xr-x[-rw-r--r--]src/main.c13
-rwxr-xr-x[-rw-r--r--]src/token.c0
-rwxr-xr-x[-rw-r--r--]src/tree.c0
5 files changed, 29 insertions, 16 deletions
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