New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Syntax question -- expression should be an error but seems not to be #173
Comments
The answer, as unsatisfying as it may be, is that Awk has always worked this way. I didn't look at this in great detail, but in the grammar for The One True Awk, it seems to be handled in the productions for You might want to look at the mawk grammar which is likely to be the cleanest of all. This is also likely fodder for a POSIX interpretation request. @benhoyt asked me about this privately a little while back and I gave him the same answer. Closing the issue. Thanks. |
@raygard Yes, I just ran across this in GoAWK and fixed it here: benhoyt/goawk#170 ... GoAWK uses a hand-written recursive descent parser so it this is a bit of a hack, but oh well, at least it's consistent with the other Awks now. I saw you said you're writing your own Awk version: in what language? Is the source code available? I'm curious now. :-) |
Hi @benhoyt, it's in C and will be freely available when (if?) it gets to a point I'm not ashamed for you to see it. It's got a long TODO list and probably still lotsa bugs. I spent waay too long yesterday chasing down a memory leak due to a (as usual) stupid blunder. |
@raygard Feel free to reach out via my email address on https://benhoyt.com/ if you want, and we can compare notes. I have a large test suite of my own tests in GoAWK, plus I run it against most of the onetrueawk and the Gawk test suites (at least the ones from Gawk that aren't Gawk-specific). Running it against the onetrueawk and Gawk suites really helped me find a lot of bugs/quirks. |
(I left this comment under issue #147 but raise it here in case it gets no notice there.)
Why is
'NF==2 && $0=$2'
not a syntax error?==
has higher precedence than&&
, which has higher precedence than=
. This should parse as'(NF==2 && $0) = $2'
, should it not? The left side of that assignment is not an lvalue. What am I missing?This works in the awk implementations I have on hand, but not in the one I am trying to write. If this is valid, it's a problem for my parser...
In C (similar precedence rules), this works as expected:
but (with gcc) this gets "error: lvalue required as left operand of assignment":
The text was updated successfully, but these errors were encountered: