home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!taumet!steve
- From: steve@taumet.com (Steve Clamage)
- Subject: Re: template disappointments ... (suggestions?)
- Message-ID: <1992Dec30.173230.22878@taumet.com>
- Organization: TauMetric Corporation
- References: <DSCHIEB.92Dec29133556@muse.cv.nrao.edu> <24508@alice.att.com> <1hqnd6INNe83@agate.berkeley.edu>
- Date: Wed, 30 Dec 1992 17:32:30 GMT
- Lines: 38
-
- jbuck@foucault.berkeley.edu (Joe Buck) writes:
-
- >In article <24508@alice.att.com> ark@alice.UUCP () writes:
- >>In article <DSCHIEB.92Dec29133556@muse.cv.nrao.edu> dschieb@muse.cv.nrao.edu (Darrell Schiebel) writes:
- >>> list<vector<int>> list_vec_int;
- >>
- >>Huh?? This works fine -- just remember to put a space between the
- >>two > characters so the >> won't be taken for a shift-right symbol.
-
- >This is such a common error (and is so ugly) that compiler writers
- >would be well advised to add productions to their grammar that catch
- >it, or magic that splits the >> token into two tokens in this case
- >if that fits in with the compiler's structure.
-
- >Yes, I know that the rules of lexical analysis force the >> to be one
- >token, but list<vector<int>> is a perfectly natural way of writing
- >this thing, so perhaps it should be permitted even at the cost of
- >adding an ugly rule to the grammar.
-
- It isn't quite as easy as it might appear. We discussed the lexical
- and syntactic issues extensively in the C++ Committee.
-
- In a template instantiation, the 'int' argument might be any expression,
- including one containing right shifts. If you try to allow what appears
- to be a right shift to be two closing ">" instead, you wind up with
- nondeterministic lexing/parsing, ambiguous grammars, or context-sensitive
- grammars. If you allow the above example to compile as the programmer
- intended, you will probably also allow examples to compile which
- really do contain syntax errors. This can lead to bugs which are very
- hard to find.
-
- There are already comparable lexical problems in C and C++, so we
- decided not to fix this one. The above example is ill-formed code, and
- the compiler will complain. This seems better than allowing ill-formed
- code which the compiler finds a way to accept.
- --
-
- Steve Clamage, TauMetric Corp, steve@taumet.com
-