Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!ig!arizona!gudeman From: gudeman@arizona.edu (David Gudeman) Newsgroups: comp.lang.misc Subject: Re: Language Design Message-ID: <9868@megaron.arizona.edu> Date: 24 Mar 89 08:24:23 GMT Organization: U of Arizona CS Dept, Tucson Lines: 67 In article <9170@claris.com> hearn@claris.com (Bob Hearn) writes: ]In article <9861@megaron.arizona.edu> gudeman@arizona.edu (David Gudeman) writes: ]> ]>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. ] ]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 [undeclared identifier] It sounds as though you are defining the semantics of a language as any part that cannot be described with a context free grammar. Of course this makes you trivially correct, but does not affect the opinions of people who criticize C based on a different definition of syntax and semantics. Also, you cannot treat the C grammar as a formal grammar that is only meant to accept strings from a formal language. The grammar is intended to show syntactic categories with semantic attachments. The problem of undeclared identifiers is common to many programming languages, but the typedef problem is more serious. An identifier is always parsed into category "identifier" regardless of whether it has been declared. However, typedefs are ambigous. For example: typedef int foo; int i; void f() { foo *i; ... } The K&R grammar is ambigous on how to parse this, while any C programmer would expect "i" to be a local pointer to an int. Once an identifier has been declared as a type, it should no longer be an identifier, but rather have a different syntactic class. No, this does not affect the language accepted by the grammar. But it does affect the syntactic category of the whole string "foo *i;". Because of the differences in syntactic categories, most people would say that static foo x; should be a syntax error if foo has not been typedefed. You can argue that, but like I said before, you are only defining terms to fit your views. >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? :-) The following should not be taken as a flame, I'm just making an observation: If you want to stop the discussion, you don't have to reply. It doesn't work to write an article and then suggest that no one respond to it after you have gotten in the last word.