commit e43f97dba453bde1833e5c25a9af2d2b0eaf2e0c
parent 4d7926403e6860a915d2f3de5f6fe2b297ebb2e4
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date: Wed, 26 Nov 2025 08:47:56 +0100
bc: Obey POSIX about handling newlines
POIX has strict rules about when operations should be performed
and even when we were already matching this due to the line
buffering of stdin it makes more sense to make it more explicit.
In an interactive invocation of bc, each time a <newline>
is read that satisfies the grammatical production:
input_item : semicolon_list NEWLINE
the sequential list of statements making up the semicolon_list
shall be executed immediately and any output produced by
that execution shall be written without any delay due to
buffering.
Diffstat:
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/bc.y b/bc.y
@@ -91,7 +91,8 @@ int cflag, dflag, lflag, sflag;
%token AUTO
%token PRINT
-%type <str> assign nexpr expr exprstat rel stat ary statlst cond
+%type <str> statlst scolonlst
+%type <str> assign nexpr expr exprstat rel stat ary cond
%type <str> autolst arglst parlst
%type <str> params param locals local
%type <macro> def if for while
@@ -109,13 +110,13 @@ program :
| item program {used = 0;}
;
-item : scolonlst '\n'
+item : scolonlst '\n' {writeout($1);}
| def parlst '{' '\n' autolst statlst '}' {funcode($1, $2, $5, $6);}
;
-scolonlst:
- | stat {writeout($1);}
- | scolonlst ';' stat {writeout($3);}
+scolonlst: {$$ = code("");}
+ | stat
+ | scolonlst ';' stat {$$ = code("%s%s", $1, $3);}
| scolonlst ';'
;