home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / std_unix / volume.23 / text0064.txt < prev    next >
Encoding:
Text File  |  1991-06-15  |  2.8 KB  |  67 lines

  1. Submitted-by: arnold%audiofax.com@mathcs.emory.edu (Arnold Robbins)
  2.  
  3. >In article <1991May11.224436.25175@uunet.uu.net> arnold@audiofax.com writes:
  4. >> (How do I know that        awk 'BEGIN { print "hi" } ; END { print "bye" }'
  5. >> is legal while             awk 'BEGIN { print "hi" }   END { print "bye" }'
  6. >> isn't?  Presenting a grammar for the language is almost a necessity...)
  7.  
  8. In article <1991May13.222855.9433@uunet.uu.net> peter@ficc.ferranti.com (Peter da Silva) writes:
  9. >It isn't? I use the latter all the time!
  10.  
  11. History lesson time.   First of all, posix awk is "new" awk, not old awk.
  12. It is based on the awk in the 1988 book by Aho, Weinberger and Kernighan.
  13. It has some additional features that have gone in to both att & gnu awk.
  14.  
  15. One of the things that happened when new awk was first realeased was a lot
  16. of cleaning up and consistencizing (if I may coin a term) of the awk language.
  17. In particular, rules had to be seperated by either a newline or a semi-colon,
  18. just like the statements inside an action.  Here's a real live example
  19. from my V.3.2 system:
  20.  
  21.     Script started on Tue May 14 12:25:28 1991
  22.     audiofax1> rlogin tiktok
  23.     Password:
  24.     
  25.     ESIX System 5.3.2 Rev.D
  26.     Copyright (C) 1984, 1986, 1987, 1988 AT&T
  27.     Copyright (C) 1987, 1988 Microsoft Corp.
  28.     Copyright (C) 1988, 1989, 1990 Everex Systems, Inc.
  29.     All Rights Reserved
  30.     Login last used: Tue May 14 12:24:29 1991
  31.     TERM=at386
  32.     tiktok> nawk 'BEGIN { print "hi" } ; END { print "bye" }' /dev/null
  33.     hi
  34.     bye
  35.     tiktok> nawk 'BEGIN { print "hi" }  END { print "bye" }' /dev/null 
  36.     nawk: syntax error at source line 1
  37.      context is
  38.             BEGIN { print "hi" }  >>>  END <<<  { print "bye" }
  39.     nawk: bailing out at source line 1
  40.     tiktok> 
  41.     Connection closed.
  42.     audiofax1> 
  43.     script done on Tue May 14 12:26:28 1991
  44.  
  45. Based on a cursory reading of the grammar in the posix spec, this rule
  46. applies.
  47.  
  48. Alas, some time back, backwards compatibility reared it's ugly head within
  49. AT&T, and for V.4 nawk, Brian Kernighan "fixed" things so that the seperator
  50. is no longer necessary.  (This was at the request of the System V folks.)
  51. David Trueman went ahead and fixed gawk to be the same way (adding heavily
  52. to the number of shift/reduce conflicts in the grammar).
  53.  
  54. So, the upshot is that technically, leaving out the semi-colon or newline
  55. is not legal, but most likely you can get away with it.
  56. -- 
  57. Arnold Robbins                 AudioFAX, Inc. | Threads are the
  58. 2000 Powers Ferry Road, Suite 200 / Marietta, GA. 30067 | lack of an idea.
  59. INTERNET: arnold@audiofax.com  Phone:   +1 404 618 4281 |     -- Rob Pike
  60. UUCP:      emory!audfax!arnold  Fax-box: +1 404 618 4581 |
  61.  
  62. [ I think this discussion is getting more towards the realm of 
  63.   comp.unix.questions.  I'm keeping this part of it here because it is
  64.    related to *nix standards and a good example of how fun they are. -- mod ]
  65. Volume-Number: Volume 23, Number 68
  66.  
  67.