home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / compiler / 1547 < prev    next >
Encoding:
Internet Message Format  |  1992-09-12  |  3.3 KB

  1. Xref: sparky comp.compilers:1547 comp.human-factors:2200
  2. Newsgroups: comp.compilers,comp.human-factors
  3. Path: sparky!uunet!world!iecc!compilers-sender
  4. From: raveling@Unify.com (Paul Raveling)
  5. Subject: Re: language design tradeoffs
  6. Reply-To: raveling@Unify.com (Paul Raveling)
  7. Organization: Unify Corporation (Sacramento)
  8. Date: Fri, 11 Sep 1992 20:00:21 GMT
  9. Approved: compilers@iecc.cambridge.ma.us
  10. Message-ID: <92-09-066@comp.compilers>
  11. References: <92-09-048@comp.compilers> <92-09-052@comp.compilers>
  12. Keywords: design, parse, comment
  13. Sender: compilers-sender@iecc.cambridge.ma.us
  14. Lines: 75
  15.  
  16. torbenm@diku.dk (Torben AEgidius Mogensen) writes:
  17. > Several languages (e.g. Miranda) use EOL as separator. It gives an
  18. > uncluttered syntax, but requires special structure if command or
  19. > expressions can't fit on a line.
  20.  
  21. Once long ago this was considered easier than using a terminator such as
  22. ';' -- a prime example was FORTRAN.  How many remember the thrill of
  23. having their IBM FORTRAN II compiler patched to recognize record-mark (a
  24. 0-2-8 punch) as a statement terminator, making it possible to punch TWO
  25. statements per card?
  26.  
  27. For a more modern and widespread example, there's the C preprocessor,
  28. where macros are parsed as one line, though they're often written as
  29. multiple lines ending with '\'.
  30.  
  31. Actually I like the idea of using EOL rather than ;.  It eliminates a
  32. cause of several common errors in compilation that need not happen, and it
  33. need not have particularly adverse side effects.
  34.  
  35. Here's one example of a human factors trap in C that wouldn't be there
  36. without ';'.  The key is C's syntax definition for <statement> -- either
  37. one simple statement terminated by ';' or a sequence of simple statements
  38. surrounded by {}'s.
  39.  
  40.     #define    SOME_MACRO(A,B) \
  41.         xxx;        /* one simple C statement */
  42.  
  43.        is syntactically interchangeable with:
  44.  
  45.     #define    SOME_MACRO(A,B) \
  46.         { xxx; yyy; }    /* one compound C statement */
  47.  
  48.  
  49.     Now take this invocation:
  50.  
  51.     if ( a == b )
  52.         SOME_MACRO(a,b)
  53.     else
  54.         ...
  55.  
  56. But if your brain kicked in with the notion that SOME_MACRO(a,b)
  57. invocation looks like it should be a statement, and you automatically
  58. coded it as
  59.  
  60.      if ( a == b )
  61.         SOME_MACRO(a,b);
  62.     else
  63.         ...
  64.  
  65. then the extra ';' terminates the entire 'if' statement and the following
  66. 'else' produces a syntax error.  Or if you had left yourself open to the
  67. dangling else problem in nested if's, it's possible to get no syntax error
  68. but instead to get a surprising flow of control.
  69.  
  70. There's a second-level trap here too, based on using knowledge of
  71. semicolons in software tools.  I once saw someone encounter the trap above
  72. when his automatic-indenting software demanded that the macro invocation
  73. look like a statement, ending with a ';'.  To accommodate this autoindent
  74. software he took existing code that had been correct and appended a ';' to
  75. each macro invocation.  At least it caused no harm on MOST of the macro
  76. invocations...
  77.  
  78. But the whole thing isn't a problem if an unescaped EOL is a statement
  79. terminator.
  80. ------------------
  81. Paul Raveling
  82. Raveling@Unify.com
  83. [For people who don't know, there are straightforward albeit ugly ways around
  84. the if, macro, and semicolon problem, e.g.:
  85. #define foo(args) if(1) { /* macro body */ } else
  86. -John]
  87. -- 
  88. Send compilers articles to compilers@iecc.cambridge.ma.us or
  89. {ima | spdcc | world}!iecc!compilers.  Meta-mail to compilers-request.
  90.