diff options
author | kdx <kikoodx@paranoici.org> | 2023-01-19 05:05:34 +0100 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-01-19 05:05:34 +0100 |
commit | 2c22cfc40c3521d31ebdab8269cd512496fd222a (patch) | |
tree | 747627db12cc1afecd6f2bfa4b1594bda006a8cc | |
parent | 8150144a228692272fd181d2ebc1041b45fde032 (diff) | |
download | golem-2c22cfc40c3521d31ebdab8269cd512496fd222a.tar.gz |
cool test
-rw-r--r-- | Token.c | 2 | ||||
-rw-r--r-- | Token.h | 2 | ||||
-rw-r--r-- | lexer.c | 2 | ||||
-rw-r--r-- | test | 30 |
4 files changed, 33 insertions, 3 deletions
@@ -26,11 +26,13 @@ void token_print(const Token *tok) case TOK_CURL_CLOS: printf("TOK_CURL_CLOS\n"); break; case TOK_SQUAR_OPEN: printf("TOK_SQUAR_OPEN\n"); break; case TOK_SQUAR_CLOS: printf("TOK_SQUAR_CLOS\n"); break; + case TOK_COLON: printf("TOK_COLON\n"); break; case TOK_SEMICOLON: printf("TOK_SEMICOLON\n"); break; case TOK_ASSIGN: printf("TOK_ASSIGN\n"); break; case TOK_COMMA: printf("TOK_COMMA\n"); break; case TOK_COMP_LESS: printf("TOK_COMP_LESS\n"); break; case TOK_MODULO: printf("TOK_MODULO\n"); break; + case TOK_STAR: printf("TOK_STAR\n"); break; case TOK_INCREMENT: printf("TOK_INCREMENT\n"); break; default: printf("token_print TODO: type %d\n", tok->type); break; } @@ -13,11 +13,13 @@ enum { TOK_CURL_CLOS, TOK_SQUAR_OPEN, TOK_SQUAR_CLOS, + TOK_COLON, TOK_SEMICOLON, TOK_ASSIGN, TOK_COMMA, TOK_COMP_LESS, TOK_MODULO, + TOK_STAR, /* double char toks */ TOK_INCREMENT, }; @@ -25,11 +25,13 @@ static unsigned int one_wide_tok(const char *s) case '}': return TOK_CURL_CLOS; case '[': return TOK_SQUAR_OPEN; case ']': return TOK_SQUAR_CLOS; + case ':': return TOK_COLON; case ';': return TOK_SEMICOLON; case '=': return TOK_ASSIGN; case ',': return TOK_COMMA; case '<': return TOK_COMP_LESS; case '%': return TOK_MODULO; + case '*': return TOK_STAR; default: return TOK_NONE; } } @@ -1,5 +1,29 @@ -int main(void) { - for (int i = 0; i < 10; i++) { - printf("%d\n", i); +fn main(argc: int, argv: **argv) int; + +fn main(argc: int, argv: **argv) int +{ + if (argc != 2) { + fprintf(stderr, "usage: %s <file>\n", argv[0]); + return 1; } + const fp: *FILE = fopen(argv[1], "rb"); + if (fp == null) { + perror("main"); + return 1; + } + const data: *char = drain(fp); + fclose(fp); + if (data == null) { + fprintf(stderr, "failed to drain '%s'\n", argv[1]); + return 1; + } + const toks: *Token = lexer(data); + free(data); + if (toks == null) { + fprintf(stderr, "lexer failed\n"); + return 1; + } + lexer_print(toks); + lexer_free(toks); + return 0; } |