From a2525f2fc3f41c792065e61079e8e7126210529e Mon Sep 17 00:00:00 2001 From: ubq323 Date: Wed, 26 Jun 2024 12:09:30 +0100 Subject: parse multiple expressions --- Makefile | 4 ++-- com.c | 19 +++++++++++++------ read.c | 14 -------------- read.h | 9 --------- tests/multi.bth | 3 +++ tests/multi.out | 3 +++ 6 files changed, 21 insertions(+), 31 deletions(-) delete mode 100644 read.c delete mode 100644 read.h create mode 100644 tests/multi.bth create mode 100644 tests/multi.out diff --git a/Makefile b/Makefile index e81ea76..6a04158 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -CS=ast.c com.c dis.c ht.c mem.c prs.c read.c state.c val.c vm.c -HS=ast.h chunk.h com.h dis.h ht.h mem.h prs.h read.h state.h util.h val.h vm.h +CS=ast.c com.c dis.c ht.c mem.c prs.c state.c val.c vm.c +HS=ast.h chunk.h com.h dis.h ht.h mem.h prs.h state.h util.h val.h vm.h CFLAGS=$(EXTRA_CFLAGS) -g -O3 -lm -Wall -Wpedantic -Werror=implicit-function-declaration bth: $(CS) $(HS) Makefile diff --git a/com.c b/com.c index 66d3941..8102497 100644 --- a/com.c +++ b/com.c @@ -6,8 +6,8 @@ #include "mem.h" #include "chunk.h" #include "ast.h" -#include "read.h" #include "util.h" +#include "prs.h" #define BYTECODE(C) (C->ch->bc) @@ -473,17 +473,24 @@ int main(int argc, char **argv) { } } - AstNode an = read(); Compiler com = (Compiler){ 0 }; com.S = S; com.ch = &ch; - Compiler *C = &com; - compile_node(C, an); - compile_opcode(C, OP_PUTS); - compile_opcode(C, OP_HALT); + AstNode an; + memset(&an, 0, sizeof an); + pcc_context_t *parser = pcc_create(NULL); + int rv; + do { + rv = pcc_parse(parser, &an); + compile_node(&com, an); + } while (rv != 0); + pcc_destroy(parser); + + compile_opcode(&com, OP_PUTS); + compile_opcode(&com, OP_HALT); Thread th = thread_new(S); th.ch = &ch; diff --git a/read.c b/read.c deleted file mode 100644 index 016ef62..0000000 --- a/read.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include - -#include "read.h" - -AstNode read() { - AstNode ret; - memset(&ret, 0, sizeof ret); - pcc_context_t *ctx = pcc_create(NULL); - pcc_parse(ctx, &ret); - pcc_destroy(ctx); - return ret; -} - diff --git a/read.h b/read.h deleted file mode 100644 index b47edb0..0000000 --- a/read.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef _read_h -#define _read_h - -#include "prs.h" -#include "ast.h" - -AstNode read(); - -#endif diff --git a/tests/multi.bth b/tests/multi.bth new file mode 100644 index 0000000..49691ce --- /dev/null +++ b/tests/multi.bth @@ -0,0 +1,3 @@ +(puts "hello") +(puts "world") +nil diff --git a/tests/multi.out b/tests/multi.out new file mode 100644 index 0000000..ecb6945 --- /dev/null +++ b/tests/multi.out @@ -0,0 +1,3 @@ +hello +world +nil -- cgit v1.2.3