summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2019-09-02 12:29:15 -0400
committerJakob Kaivo <jkk@ung.org>2019-09-02 12:29:15 -0400
commit98bcc06abc0bc38859532052a5782178f4217a19 (patch)
treed34e58f34e327b11f2a2ef50274242901bd00a9a
parent8ab5902d2cb66809d478ef795a878a413dea41cc (diff)
handle newline better, - does subtraction, don't crash on ^D
-rw-r--r--bc.y7
1 files changed, 6 insertions, 1 deletions
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) {