jeenglis@alcor.usc.edu (Joe English) (03/05/90)
ned@MCC.COM (Ned Nowotny) writes: >Given the imprecise nature of the C++ specification, I am more than a >little disappointed that the language does not have a grammar expressible >in BNF form that will accept all legal strings and reject all illegal >strings. (That, by the way, is what I consider to be the test of whether >a given language is specifiable by a given grammar. By your definition, most traditional programming languages aren't specifiable by context-free grammars. CFGs aren't powerful enough to do type-checking, making sure that identifiers are declared before they are used, etc. >While it may be >true that some LALR(1) grammar will accept all legal C++ strings, the fact >that the grammar must also accept illegal strings makes the claim that >C++ is somehow a LALR(1) language something less than useful.) It is possible to write a LALR(1) grammar that rejects illegal inputs (ignoring type-checking and other semantic issues, that is); the problem is that certain input strings are ambiguous, like the example Bjarne Stroustrup cited. (The only complaint I have about that is that if a compiler has to do infinite lookahead to disambiguate input strings, then human beings reading the program have to as well.) --Joe English jeenglis@nunki.usc.edu