xref: /illumos-gate/usr/src/test/util-tests/tests/awk/gnu/parse1.awk (revision 2aeafac3612e19716bf8164f89c3c9196342979c)
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