xref: /illumos-gate/usr/src/test/util-tests/tests/awk/gnu/parse1.awk (revision 3cac7b0d73edf3f2674ad0f64d1fff3d2e59ae8c)
1# Date: Fri, 06 Jan 2006 14:02:17 -0800
2# From: Paul Eggert <eggert@CS.UCLA.EDU>
3# Subject: gawk misparses $expr++ if expr ends in ++
4# To: bug-gawk@gnu.org
5# Message-id: <87irsxypzq.fsf@penguin.cs.ucla.edu>
6#
7# Here's an example of the problem:
8#
9# $ gawk 'BEGIN{a=3}{print $$a++++}'
10# gawk: {print $$a++++}
11# gawk:               ^ syntax error
12#
13# But it's not a syntax error, as the expression conforms to the POSIX
14# spec: it should be treated like '$($a++)++'.
15#
16# Mawk, Solaris awk (old awk), and Solaris nawk all accept the
17# expression.  For example:
18#
19# $ echo '3 4 5 6 7 8 9' | nawk 'BEGIN{a=3}{print $$a++++}'
20# 7
21#
22# This is with gawk 3.1.5 on Solaris 8 (sparc).
23#
24#
25# #####################################################################################
26# This Mail Was Scanned by 012.net AntiVirus Service1- Powered by TrendMicro Interscan
27#
28BEGIN { a = 3 }
29
30{
31	print "in:", $0
32	print "a =", a
33	print $$a++++
34	print "out:", $0
35}
36