From 463690390b45ddd96545ae958e2605e262966c9f Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Mon, 11 Oct 2021 19:33:29 +0200 Subject: Add a new version of the lexer for token gen --- src/bootstrap/main.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/bootstrap/main.c') diff --git a/src/bootstrap/main.c b/src/bootstrap/main.c index 662831e..113ee48 100755 --- a/src/bootstrap/main.c +++ b/src/bootstrap/main.c @@ -5,10 +5,19 @@ #include "string_view.c" #include "read_line.c" +#include "lexer.c" void process_source(const StringView *source) { - sv_write(source, stdout); + Tokens tokens = tokenize(source); + + // Print tokens. + for (size_t i = 0; i < tokens.size; i++) { + Token tok = tokens.buf[i]; + print_token(tok); + } + + free(tokens.buf); } #define REPL_PROMPT "bdl> " @@ -57,13 +66,13 @@ run_file(char *file_name) { fclose(file); } -#define STDIN_BUF_SIZE 16 +#define STDIN_BUF_CAP 16 void run_stdin(void) { size_t buf_size = 0; - size_t buf_cap = STDIN_BUF_SIZE; - char *source = malloc(sizeof(char) * buf_cap); + size_t buf_cap = STDIN_BUF_CAP; + char *source = malloc(buf_cap * sizeof(char)); char c; while ((c = getchar()) != EOF) { -- cgit v1.2.1