[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
parsing getline var argument
From: |
Joel E. Denny |
Subject: |
parsing getline var argument |
Date: |
Sun, 12 Aug 2007 20:17:35 -0400 (EDT) |
I am trying to understand GNU AWK's parser as it relates to an extension I
am working on for Bison. However, I don't use AWK often, so some of my
questions may be naive.
I checked out GNU AWK from CVS and built it. The most recent ChangeLog
entry at the time was Sat Aug 11 22:48:11 2007.
I then ran:
% ./gawk '{getline $4; print $4;}' > stdout
line 1
line 2
% cat stdout
line2
Recent releases of GAWK behave in the same way, but this behavior differs
from /usr/bin/awk under Solaris 10:
% /usr/bin/awk '{getline $4; print $4;}' > stdout
line 1
line 2
% od -c stdout
0000000 \n
0000001
What is the correct behavior? Is `getline $4;' a GNU extension? Or is
the behavior undefined here?
If CVS GAWK is correct, then how should it parse the following expression?
getline $4*0;
In Makefile, I added -DGAWKDEBUG to CFLAGS. I then rebuilt GAWK and ran:
% ./gawk --parsedebug 'getline $4*0;'
>From the parser trace, I see that GAWK parses the expression as:
(getline $4)*0;
For example:
% ./gawk '{ print getline $4; print getline $4*0; }' > stdout
line 1
line 2
line 3
% cat stdout
1
0
However:
% /usr/bin/awk '{ print getline $4; print getline $4*0; }' > stdout
line 1
line 2
line 3
% cat stdout
1
10
What behavior is correct?
Thanks.
- parsing getline var argument,
Joel E. Denny <=