• A niggling bug in the GAWK parser

    From Kenny McCormack@21:1/5 to All on Tue Oct 5 16:27:54 2021
    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
    it could be caught better. In fact, it took me more than a few moments to figure out that it wasn't a syntax error (in the conventional sense).
    I.e., there wasn't really anything wrong with my code - I hadn't misspelled anything or anything like that. Rather, it is just a (well-known) bugaboo.

    Note: Tested with GAWK 5.0.1 - it is still there and still flagged as
    "syntax error".

    Anyway, just something to consider. Note that C compilers these days are getting really explicit about telling you exactly what they think is wrong
    with your code - and how to fix it. It seems GAWK might take a cue from that...

    --
    To be evangelical is to spend every waking moment hovering around
    two emotional states: fear and rage. Evangelicals are seriously the
    angriest and most vicious bunch of self-pitying, constantly-moaning
    whinybutts I've ever encountered.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mack The Knife@21:1/5 to Kenny McCormack on Wed Oct 6 12:05:09 2021
    From https://www.gnu.org/software/gawk/manual/html_node/Usenet.html:

    | Please do not try to report bugs in gawk by posting to the Usenet/Internet
    | newsgroup comp.lang.awk. Although some of the gawk developers occasionally
    | read this news group, the primary gawk maintainer no longer does. Thus
    | it’s virtually guaranteed that he will not see your posting.

    Also, you might think about the kind of work involved in such changes
    to the parser, and in particular about the size and nature (paid)
    of the teams doing GCC development vs. the size and nature (volunteer)
    of the team doing gawk development.

    'nuff said.

    In article <sjhuea$2v60b$1@news.xmission.com>,
    Kenny McCormack <gazelle@shell.xmission.com> 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
    it could be caught better. In fact, it took me more than a few moments to >figure out that it wasn't a syntax error (in the conventional sense).
    I.e., there wasn't really anything wrong with my code - I hadn't misspelled >anything or anything like that. Rather, it is just a (well-known) bugaboo.

    Note: Tested with GAWK 5.0.1 - it is still there and still flagged as
    "syntax error".

    Anyway, just something to consider. Note that C compilers these days are >getting really explicit about telling you exactly what they think is wrong >with your code - and how to fix it. It seems GAWK might take a cue from >that...

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kenny McCormack@21:1/5 to 480-992-1380@kylheku.com on Wed Oct 6 16:14:20 2021
    In article <20211006081936.667@kylheku.com>,
    Kaz Kylheku <480-992-1380@kylheku.com> wrote:
    ...
    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.

    Very interesting. Thanks.

    --
    No puppet.
    No puppet.
    You're a puppet.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Kenny McCormack on Wed Oct 6 15:21:25 2021
    On 2021-10-05, Kenny McCormack <gazelle@shell.xmission.com> 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)
  • From Ed Morton@21:1/5 to Mack The Knife on Wed Oct 6 11:52:59 2021
    On 10/6/2021 7:05 AM, Mack The Knife wrote:
    <snip>
    Kenny McCormack <gazelle@shell.xmission.com> wrote:
    I got bit by this today:

    print SomeVar > stime ? "Error!" : "OK"

    Perfectly reasonable, right?

    Wrong

    But GAWK flags this as a syntax error.

    Good. Any unparenthesized expression on the right side of input or
    output redirection is undefined behavior per POSIX and a syntax error is
    a good response to that code.

    Ed.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)