From df8846173b672e66177aea6b3fe37ec4af5428e9 Mon Sep 17 00:00:00 2001 From: s-over-4 Date: Tue, 13 Jun 2023 17:31:21 -0400 Subject: ok --- halk | Bin 30720 -> 30856 bytes src/include/token.h | 2 ++ src/main.c | 10 ++++---- src/token.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/util.c | 3 --- 5 files changed, 71 insertions(+), 8 deletions(-) diff --git a/halk b/halk index bb60538..efb2401 100755 Binary files a/halk and b/halk differ diff --git a/src/include/token.h b/src/include/token.h index a42b81f..f05e962 100644 --- a/src/include/token.h +++ b/src/include/token.h @@ -38,6 +38,8 @@ typedef struct TOKEN_STRUC { token_t* token_init(int type, char* val); +char* token_get_type(int type); + int char_could_start_keyword(char* character); int char_could_split_keyword(char* character); int char_could_start_int(char* character); diff --git a/src/main.c b/src/main.c index 37f37bf..d98b98d 100644 --- a/src/main.c +++ b/src/main.c @@ -1,17 +1,17 @@ #include #include - #include "include/util.h" +#include "include/token.h" #include "include/lexer.h" int main(int argc, char* argv[]) { - FILE *fsource; + FILE* fsource; long fsource_size; - char *source; + char* source; - fsource = fopen("examples/simple.halk", "rb"); + fsource = fopen(argv[1], "rb"); if (!fsource) { die("source file not found"); }; @@ -45,7 +45,7 @@ int main(int argc, char* argv[]) { token_t* token = NULL; while ((token = lexer_get_next_token(lexer)) != NULL) { - log_inf("token type: [%d]\ttoken value: [%s]", token->type, token->value); + log_inf("token type: [%s]\ttoken value: [%s]", token_get_type(token->type), token->value); free(token); } diff --git a/src/token.c b/src/token.c index 6bba2b9..079a59f 100644 --- a/src/token.c +++ b/src/token.c @@ -12,6 +12,70 @@ token_t* token_init(int type, char* val) { return token; } +char* token_get_type(int type) { + switch (type) { + case TOKEN_KEYWORD: + return "TOKEN_KEYWORD"; + break; + case TOKEN_PRIM_STR: + return "TOKEN_PRIM_STR"; + break; + case TOKEN_PRIM_INT: + return "TOKEN_PRIM_INT"; + break; + case TOKEN_COMM: + return "TOKEN_COMM"; + break; + case TOKEN_EXPR_END: + return "TOKEN_EXPR_END"; + break; + case TOKEN_LGROUP: + return "TOKEN_LGROUP"; + break; + case TOKEN_RGROUP: + return "TOKEN_RGROUP"; + break; + case TOKEN_DIRECTIVE: + return "TOKEN_DIRECTIVE"; + break; + case TOKEN_FN_APPLY: + return "TOKEN_FN_APPLY"; + break; + case TOKEN_LIST_DELIM: + return "TOKEN_LIST_DELIM"; + break; + case TOKEN_DEF_TAG: + return "TOKEN_DEF_TAG"; + break; + case TOKEN_BLOCK_START: + return "TOKEN_BLOCK_START"; + break; + case TOKEN_BLOCK_END: + return "TOKEN_BLOCK_END"; + break; + case TOKEN_NAMESPACE_DELIM: + return "TOKEN_NAMESPACE_DELIM"; + break; + case TOKEN_ARRAY_START: + return "TOKEN_ARRAY_START"; + break; + case TOKEN_ARRAY_END: + return "TOKEN_ARRAY_END"; + break; + case TOKEN_DEF_SET: + return "TOKEN_DEF_SET"; + break; + case TOKEN_UNKNOWN: + return "TOKEN_UNKNOWN"; + break; + case TOKEN_EOF: + return "TOKEN_EOF"; + break; + default: + return "???"; + } +} + int char_could_start_keyword(char* character) { for (int i = 0; i < TOKEN_DEFNAME_FIRST_CHAR_ALLOWED_CHARS_LEN; ++ i) { if (TOKEN_DEFNAME_FIRST_CHAR_ALLOWED_CHARS[i] == *character) { diff --git a/src/util.c b/src/util.c index b4a2e15..1a7d256 100644 --- a/src/util.c +++ b/src/util.c @@ -35,12 +35,9 @@ void log_inf(const char* fmt, ...) { void log_raw(const char* fmt, ...) { va_list ap; - va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap); - - fprintf(stderr, "\n"); } void log_war(const char* fmt, ...) { -- cgit v1.2.3