home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / cplus / 18631 < prev    next >
Encoding:
Text File  |  1993-01-02  |  3.3 KB  |  80 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
  3. From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
  4. Subject: Re: template disappointments ... (suggestions?)
  5. Message-ID: <1993Jan2.081410.22955@ucc.su.OZ.AU>
  6. Sender: news@ucc.su.OZ.AU
  7. Nntp-Posting-Host: extro.ucc.su.oz.au
  8. Organization: MAXTAL P/L C/- University Computing Centre, Sydney
  9. References: <1992Dec30.173230.22878@taumet.com> <1992Dec31.150138.22342@netcom.com> <1993Jan1.170812.26511@taumet.com>
  10. Date: Sat, 2 Jan 1993 08:14:10 GMT
  11. Lines: 67
  12.  
  13. In article <1993Jan1.170812.26511@taumet.com> steve@taumet.com (Steve Clamage) writes:
  14. >erc@netcom.com (Eric Smith) writes:
  15. >
  16. >>In article <1992Dec30.173230.22878@taumet.com> steve@taumet.com (Steve Clamage) writes:
  17. >>How is >> different from > in that respect?  a>b is a perfectly valid
  18. >>int expression.
  19. >
  20. >The '>' is always a '>' token.  The proposal was that sometimes '>>' is
  21. >a '>>' token and sometimes it is two '>' tokens.  
  22.  
  23.     It doesnt have to be construed that way. One could just
  24. extend the grammar to allow the single >> to terminate two levels of open
  25. < brackets.
  26.  
  27. >The compiler would have
  28. >to decide which interpretation to use.  One interpretation might wind up
  29. >being unparseable only after an arbitrary number of additional tokens.
  30.  
  31.     The compiler has this same problem parsing '-' in the sense
  32. that it might be a single token "unary or binary minus" or two
  33. different tokens "unary minus" or "binary minus".
  34. >
  35. >Suppose there are several sets of '>>' in a template expression.  Each
  36. >one is a branch point for additional possible parses.  The compiler has to
  37. >verify that exactly one of a set of interpretations leads to a valid parse.
  38.  
  39.     How does this differ from '>' already causing the same problem?
  40. >
  41. >A whole new kind of parsing is therefore required just to allow
  42. >programmers to omit a blank between consecutive closing template brackets.
  43.  
  44.     You may be right, indeed it appears to me you are,
  45. but the technical question is probably whether '>>' could mean
  46. "shift or double template right bracket" and still be parsed
  47. using an LALR parser. (Is there an LALR grammar for C++ anyhow?)
  48.  
  49. >
  50. >It isn't impossible to have a language like this.  The question, as
  51. >always, is whether the additional compiler complexity and other
  52. >disadavantages are outweighed by the advantages.  The decision in C
  53. >and C++ has always been to choose context-free lexical analysis and
  54. >the "maximum munch" lexical rule.
  55.  
  56.     The lexical analyser would be regular surely, not context
  57. free, and the parser hopefully less than context free: a backtracking
  58. parser would have no problem with '>>', but the users waiting
  59. hours for a compile might :-)
  60.  
  61.     It is surely easy to make a rule that when two levels
  62. of < have been seen, they are closed by >>. If you really
  63. want a shift, use brackets.
  64.  
  65.     < ... < ... >> 
  66.  
  67.     < .. < ... (a>>b) .. >>
  68.  
  69.     This sort of rule is already in place for the stupid
  70. comma operator. I'm certainly not suggesting we do this,
  71. but it would be interesting to establish whether '>>'
  72. can be implemented using the same sort of parsers
  73. currently used for C++.
  74.  
  75. -- 
  76. ;----------------------------------------------------------------------
  77.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  78.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  79. ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  80.