From 6506e5c3d24f01b3a662a58884e210f4c9e023b8 Mon Sep 17 00:00:00 2001 From: Felix Perktold Date: Sat, 20 Dec 2025 22:43:37 +0100 Subject: cleanup --- Makefile | 1 + lisp.c | 2 +- lisp.y | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 2dc8a02..4ff9837 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ YACC = bison CC = gcc -g CFLAGS = -DYYDEBUG=1 LIBS = -lreadline -lfl -lm +.SUFFIXES: lisp: lisp.c lisp.tab.o lex.yy.o $(CC) $(CFLAGS) -o $@ lisp.c lisp.tab.o lex.yy.o $(LIBS) diff --git a/lisp.c b/lisp.c index e6dc02e..cbd92b2 100644 --- a/lisp.c +++ b/lisp.c @@ -87,7 +87,7 @@ int main(void) { char* line; while ((line = readline("λ > ")) != NULL) { if (*line) add_history(line); - yy_scan_string(line); // feed input to Flex/Bison + yy_scan_string(line); yyparse(); free(line); } diff --git a/lisp.y b/lisp.y index 29031a4..c2ca8f5 100644 --- a/lisp.y +++ b/lisp.y @@ -23,7 +23,7 @@ static int is_integer(double x) { %token LPAREN RPAREN DOT WHITESPACE %token PLUS MINUS MULT DIV -%type sexpr atom sexprs +%type sexpr atom %start sexprs @@ -31,8 +31,8 @@ static int is_integer(double x) { opt_ws: /* matches no whitespace */ | WHITESPACE; -sexprs: sexpr - | sexprs opt_ws sexpr; +sexprs: sexpr { print_val($1); printf("\n"); } + | sexprs opt_ws sexpr { print_val($3); }; sexpr: atom | LPAREN opt_ws sexpr opt_ws DOT opt_ws sexpr opt_ws RPAREN -- cgit v1.2.3