From 98bcc06abc0bc38859532052a5782178f4217a19 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Mon, 2 Sep 2019 12:29:15 -0400 Subject: handle newline better, - does subtraction, don't crash on ^D --- bc.y | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bc.y b/bc.y index 76666e4..4f57ba4 100644 --- a/bc.y +++ b/bc.y @@ -54,6 +54,7 @@ program input_item : semicolon_list NEWLINE { + bc_print(bc_eval($1)); } | function ; @@ -172,7 +173,7 @@ expression $$ = bc_operation(ADD, $1, $3); } | expression SUB_OP expression { - $$ = bc_operation(ADD, $1, $3); + $$ = bc_operation(SUB, $1, $3); } | expression MUL_OP expression { $$ = bc_operation($2, $1, $3); @@ -221,6 +222,10 @@ static char **files; int yywrap(void) { + if (files == NULL || files[optind] == NULL) { + return 1; + } + char *file = files[optind++]; if (yyin != stdin) { -- cgit v1.2.1