🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #6349

Re: Language Design

#6349
From: Bob Hearn
Date: Fri, 24 Mar 1989 00:12
51 lines
2418 bytes
In article <9861@megaron.arizona.edu> gudeman@arizona.edu (David Gudeman) writes:
>I agree, that this is founded on misunderstandings, but I think you've
>got the wrong misunderstanding.  I believe that C's grammar is _not_,
>in fact context free, though the grammar in K&R is.  How can this be?
>I'm glad you asked.  The grammar given in K&R isn't technically
>correct.  Don't take offense, I'm not making a judgement on this
>practice, just pointing it out.
>
>One inaccuracy is in the production
>
>	typedef-name : identifier
>
>I don't know if there are others.  "typedef-name" occurs in the production
>
>	type-specifier: ... | typedef-name
>
>and a mechanical reading of this implies that _any_ identifier can
>occur as a type-specifier.  This is not the case.  In fact, an
>identifier can only be a type-specifier if it has previously been
>declared with a typedef.  I can't prove it, but I believe you need a
>context-sensitive grammar to specify this.
>

Yes, this is another big misunderstanding in this discussion... I would
say that the *grammar* stipulates that a type-specifier can be an
identifier, but the *semantics* specifies that this results in a valid
program only when the identifier is a valid type name.  This is really
the same problem as

{
    .
    .
    x = 1;
    . 
    .
}

which is correct only if x has been previously declared.  I think here
one would always call this an undeclared identifier error, a type of
semantic error, rather than a syntax error.  And you're quite right that
it takes a context-sensitive grammar to generate the set of VALID C programs
in this sense!  My point is that this is true for just about any language
you can name, and there is nothing particularly odd about this aspect
of C.

In any case, this discussion is getting old... I vote we talk about something
new.  This is comp.lang.misc, not comp.lang.C.grammar, right? :-)
So, anyone designed any good languages lately?

Bob Hearn
hearn@claris.com
Technical Details
Message-ID: <9170@claris.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!apple!claris!hearn
References: <9861@megaron.arizona.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!apple!claris!hearn
From: hearn@claris.com (Bob Hearn)
Newsgroups: comp.lang.misc
Subject: Re: Language Design
Message-ID: <9170@claris.com>
Date: 24 Mar 89 00:12:40 GMT
References: <9861@megaron.arizona.edu>
Reply-To: hearn@claris.com (Bob Hearn)
Organization: Claris Corporation, Mountain View CA
Lines: 51