Re: language twiddling, was Infinite look ahead required by C++?

Robert A Duff <bobduff@shell01.TheWorld.com>
Fri, 05 Mar 2010 18:07:17 -0500

          From comp.compilers

Related articles
[2 earlier articles]
Re: Infinite look ahead required by C++? ng2010@att.net (ng2010) (2010-02-23)
Re: Infinite look ahead required by C++? cfc@shell01.TheWorld.com (Chris F Clark) (2010-02-27)
Re: Infinite look ahead required by C++? bartc@freeuk.com (bartc) (2010-02-28)
Re: language twiddling, was Infinite look ahead required by C++? cfc@shell01.TheWorld.com (Chris F Clark) (2010-03-01)
Re: language twiddling, was Infinite look ahead required by C++? gah@ugcs.caltech.edu (glen herrmannsfeldt) (2010-03-03)
Re: language twiddling, was Infinite look ahead required by C++? bobduff@shell01.TheWorld.com (Robert A Duff) (2010-03-05)
Re: language twiddling, was Infinite look ahead required by C++? bobduff@shell01.TheWorld.com (Robert A Duff) (2010-03-05)
Re: language twiddling, was Infinite look ahead required by C++? cfc@shell01.TheWorld.com (Chris F Clark) (2010-03-07)
Re: language twiddling, was Infinite look ahead required by C++? bartc@freeuk.com (bartc) (2010-03-08)
Re: language twiddling, was Infinite look ahead required by C++? cfc@shell01.TheWorld.com (Chris F Clark) (2010-03-10)
Re: language twiddling, was Infinite look ahead required by C++? bobduff@shell01.TheWorld.com (Robert A Duff) (2010-03-12)
Re: language twiddling, was Infinite look ahead required by C++? nevillednz@gmail.com (Neville Dempsey) (2010-03-14)
Re: language twiddling, was Infinite look ahead required by C++? genew@ocis.net (Gene Wirchenko) (2010-04-14)
[3 later articles]
| List of all articles for this month |

From: Robert A Duff <bobduff@shell01.TheWorld.com>
Newsgroups: comp.compilers
Date: Fri, 05 Mar 2010 18:07:17 -0500
Organization: The World Public Access UNIX, Brookline, MA
References: 10-02-024 10-02-039 10-02-086 10-02-088 10-03-003 10-03-005 10-03-007
Keywords: parse, design
Posted-Date: 05 Mar 2010 23:34:53 EST

glen herrmannsfeldt <gah@ugcs.caltech.edu> writes:


> Both Fortran and PL/I have no reserved words. I am not so sure
> about Fortran, but it seems to have been intentional for PL/I.
> A large list of reserved words (reference COBOL) means that
> programmers have to know those words, even if they don't need
> those features.


Not really. A programmer doesn't need to memorize all the reserved
words. They can just write code, and fix it when the compiler
complains "you tried to declare a procedure whose name is a reserved
word".


At least that's true if the compiler can give such good error
messages, which depends to some extent on the language being
designed to make that easy. If misuse of a reserved word
results in "syntax error, compiler is confused", as it does
all too often, then my claim above is wrong.


>...C has a relatively small list if you don't
> include names reserved for the library, but they are still there.
>
> Also, the use of reserved words complicates adding new features
> to the language later.


One possibility is to make commonly-used syntactic keywords
(like "begin" or "procedure" in Pascal) reserved,
but other keywords (including ones added during language
revision) not reserved.


>...Adding new reserved words can make old
> valid programs invalid.


Yes.


> (snip)
>
>> The reason I recommended the person consider Pascal is that it has
>> all those problems solved and solved simply. C is not a
>> particularly easy language to parse. If you go trying to extend C,
>> it is very easy to make the language completely unparseable. A few
>> tiny bandaids on C don't resolve those issues.
>
> As far as I know, a lot of work went into each extension of Fortran to
> make sure that no ambiguities crept in, and, except for a few specific
> exceptions, older programs would still be valid.


Sure, that's true of many languages. It is irresponsible to
do otherwise.


> In most cases, reserved words are reserved to make it easier for the
> compiler, not for the programmer.


I'm not sure that's true. I mean, a variable called "begin" in an
Ada program would damage readability. A variable called "requeue",
maybe not so much.


> I have seen C compilers that refused a variable named new. (That is,
> C/C++ compilers in C mode.)


Interesting compiler bug. ;-)


Easy to see why it happened. Also easy to fix.


- Bob



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.