On 2021-10-05, Kenny McCormack <
[email protected]> wrote:
I got bit by this today:
print SomeVar > stime ? "Error!" : "OK"
Perfectly reasonable, right? But GAWK flags this as a syntax error. (Literally, as "syntax error - and see below)
And I know why. I also know the fix (which is to parenthesize the conditional expression). So, I don't need anyone writing in to tell me why it happens or what the fix is.
The point is, it just seems to me that the error message ought to be
clearer. I mean, this one has been around a long time, and it seems like
I happen have a git directory with gawk 4.x sources from way back when,
all set up to build.
I tried a tiny patch, just for discussion:
$ ./gawk 'BEGIN { print SomeVar > stime ? "Error!" : "OK" }'
gawk: cmd. line:1: BEGIN { print SomeVar > stime ? "Error!" : "OK" }
gawk: cmd. line:1: ^ syntax error
gawk: cmd. line:1: BEGIN { print SomeVar > stime ? "Error!" : "OK" }
gawk: cmd. line:1: ^ I/O redirection possibly confused with relational operator
gawk: cmd. line:1: BEGIN { print SomeVar > stime ? "Error!" : "OK" }
gawk: cmd. line:1: ^ syntax error
It is:
$ git diff awkgram.y
diff --git a/awkgram.y b/awkgram.y
index 0b7e29f3..41952248 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -1312,6 +1312,12 @@ output_redir
yyerror(_("multistage two-way pipelines don't work"));
$$ = list_prepend($3, $1);
}
+ | IO_OUT common_exp error
+ {
+ yyerror(_("I/O redirection possibly confused with relational operator"));
+ yyerrok;
+ $$ = NULL;
+ }
;
if_statement
See what you make of it.
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)