author | Alan Dipert
<alan@dipert.org> 2024-01-09 17:03:20 UTC |
committer | Alan Dipert
<alan@dipert.org> 2024-01-09 17:03:20 UTC |
parent | 3f8a107e64bb426fbd0f16a9dc13a65b17ad19c6 |
Makefile | +2 | -2 |
main.c | +0 | -23 |
parse.c | +19 | -0 |
parse.h | +7 | -1 |
diff --git a/Makefile b/Makefile index 2c6e49a..1bb268f 100644 --- a/Makefile +++ b/Makefile @@ -11,10 +11,10 @@ all: bbasic bbasic: lex.yy.o bbasic.tab.o parse.o main.o $(CC) $(CFLAGS) -o bbasic lex.yy.o bbasic.tab.o parse.o main.o -lfl -parse.o: parse.c parse.h +parse.o: parse.c bbasic.tab.h parse.h $(CC) $(CFLAGS) -c parse.c -main.o: main.c bbasic.tab.h parse.h +main.o: main.c parse.h $(CC) $(CFLAGS) -c main.c lex.yy.o: lex.yy.c bbasic.tab.h diff --git a/main.c b/main.c index 934e9fb..f73af3f 100644 --- a/main.c +++ b/main.c @@ -1,29 +1,6 @@ #include <stdio.h> -#include "bbasic.tab.h" #include "parse.h" -extern int yyparse(); -extern void yy_scan_string(char*); -extern void yylex_destroy(); - -struct node_tag* read_line(char* line) { - int yyparse_failed; - yy_scan_string(line); - yyparse_failed = yyparse(); - yylex_destroy(); - return yyparse_failed ? NULL : ast_last_numbered_line; -} - -struct node_tag* read_line_stdin() { - char* line = NULL; - size_t len = 0; - struct node_tag* read_node; - getline(&line, &len, stdin); - read_node = read_line(line); - free(line); - return read_node; -} - void read_loop() { struct node_tag* line; while (1) { diff --git a/parse.c b/parse.c index c0422c0..34624b5 100644 --- a/parse.c +++ b/parse.c @@ -51,3 +51,22 @@ struct node_tag* ast_make_number_integer(int val) { new_node->data.number_integer.val = val; return new_node; } + +struct node_tag* read_line(char* line) { + int yyparse_failed; + yy_scan_string(line); + yyparse_failed = yyparse(); + yylex_destroy(); + return yyparse_failed ? NULL : ast_last_numbered_line; +} + +struct node_tag* read_line_stdin() { + char* line = NULL; + size_t len = 0; + struct node_tag* read_node; + getline(&line, &len, stdin); + read_node = read_line(line); + free(line); + return read_node; +} + diff --git a/parse.h b/parse.h index 0ef5be3..0d3f5ed 100644 --- a/parse.h +++ b/parse.h @@ -1,5 +1,6 @@ #include <stdio.h> #include <stdlib.h> +#include "bbasic.tab.h" enum NODE_TYPE { NODE_NUMBERED_LINE, @@ -64,4 +65,9 @@ struct node_tag* ast_make_if(struct node_tag* pred, struct node_tag* stmt); struct node_tag* ast_make_id(char *name); struct node_tag* ast_make_number_integer(int val); -extern struct node_tag* ast_last_numbered_line; +extern int yyparse(); +extern void yy_scan_string(char*); +extern void yylex_destroy(); + +struct node_tag* read_line(char* line); +struct node_tag* read_line_stdin();