Comments (3)
Hi @juntuu. FWIW, I've fixed the $++a
one in #168, and I'm planning to fix the 1&&x=1
one in #170 (which I don't love, but oh well).
from goawk.
I haven't gone through all the cases in my repo, but there are three differences (from all gawk, onetrueawk and mawk) I remember having noticed:
- the
$++a
one, that has issue open already - the one in this issue, also with logical or
||
and the augmented assignment operators+=
etc. - non-associative binary operators with assignment as the right hand side:
- comparison operators
1 < x=2
, others parse as1 < (x=2)
vs. goawk(1 < x) = 2
- regex match operators
1 ~ x=2
- comparison operators
I'm not sure what would be "the correct" parse for 2. and 3. in terms of the posix spec, but all the other major implementations seem to behave the same way.
Also the 2. and 3. might be somewhat related. At least both parse similarly (using the gawk pretty-printing option):
$ gawk -o- 'BEGIN { 1 < x=2 < y=3 }'
BEGIN {
1 < (x = 2 < (y = 3))
}
$ gawk -o- 'BEGIN { 1 && x=2 && y=3 }'
BEGIN {
1 && (x = 2 && (y = 3))
}
Going on a tangent...
I just noticed while writing this, that the handling of the non-associative operators is all over the place when there is no assignment expressions involved:
gawk accepts chaining of match-ops (left-associative), but not comparisons:
$ gawk -o- 'BEGIN { 1 ~ 2 ~ 3 }'
BEGIN {
(1 ~ 2) ~ 3
}
$ gawk -o- 'BEGIN { 1 < 2 < 3 }'
gawk: cmd. line:1: BEGIN { 1 < 2 < 3 }
gawk: cmd. line:1: ^ syntax error
onetrueawk rejects both with similar error message:
$ nawk 'BEGIN { 1 ~ 2 ~ 3 }'
nawk: syntax error at source line 1
context is
BEGIN { 1 ~ 2 >>> ~ <<<
nawk: illegal statement at source line 1
nawk: illegal statement at source line 1
and mawk accepts both (left-associative):
$ mawk -W dump 'BEGIN { 1 < 2 < 3 }'
BEGIN
000 . pushd 1
002 . pushd 2
004 . lt
005 . pushd 3
007 . lt
008 . pop
009 . exit0
In conclusion, I'd hope that any important awk code would be written in more unambiguous style 😅
from goawk.
Thanks @juntuu! After I submitted this issue I did go through all the solutions in your repo that were failing in GoAWK, and that's the list I came up with too. Yep, I figured I'd address the cond || var += value
and similar cases at the same time -- they're no doubt manifestations of the same issue.
As far as the POSIX spec goes, it says that &&
and ||
are higher-precedence than lvalue=expr
(and augmented assignment), which is how I'm parsing it. However, it also says that &&
and ||
are left-associative and lvalue=expr
is right-associative. I actually don't really know what that means! I thought that associativity was only needed when operators have the same precedence. The POSIX spec says, "In expression evaluation, where the grammar is formally ambiguous, higher precedence operators shall be evaluated before lower precedence operators." I'll have to take a closer look and improve my understanding here...
from goawk.
Related Issues (20)
- Ensure we use value of FS at the time the record was read
- Allow outputting to /dev/stderr on Windows HOT 14
- Missing support for json input files HOT 1
- CSV - loss of double quote when dataset is updated HOT 2
- After Go 1.21 is out, build with PGO enabled HOT 1
- close() on pipe command does not return exit status HOT 2
- close() on input pipe does not cleanup child process HOT 5
- system() always returns -1 if process exits due to signal
- fflush() stops on first flush error HOT 2
- Add support for new \u Unicode escape sequence
- Windows error: flag provided but not defined: -encodedCommand HOT 3
- goawk CSV mode ignores specified field separator HOT 2
- Allow line break between `}` and `while` HOT 1
- parser: Discriminate between constant and dynamic regexps HOT 3
- Support for network? HOT 3
- What's the purpose of `testdata/echo` HOT 7
- {} behaves like 1, END{} doesn't exhaust input HOT 2
- Support for %i in format strings. HOT 3
- srand() initialization without an argument. HOT 1
- Test failures on Linux/i386 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from goawk.