🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #6364

Re: Language Design, or: is C's Grammar Context Free

#6364
From: Kenneth Walker
Date: Wed, 29 Mar 1989 03:55
35 lines
1966 bytes
In article <12778@watdragon.waterloo.edu>, akwright@watdragon.waterloo.edu (Andrew K. Wright) writes:
> About "C's grammar [not] being screwed up":  with a few simple kludges
> such as recognizing typedef names in the lex, it is fairly
> easy to build a grammar which has sensible structure for C.
> Or is it?  Some points were raised about where PCC does/doesnt turn off
> typedef recognition, and this seems ill-defined.
> (Anybody know what the ANSI draft says?)

(These comments are based on the July 1988 draft.) The standard allows
typedef names to be redeclared within an inner scope:
   
   typedef int x;
   {
   char *x;
   }

The only restriction is that the type must be explicily given. That is
you cannot redeclare it like:

   static x;

One solution is to define the identifier in the declarator to
be any identifier:

any_ident: Identifier | Typedef_name;

rather than turn off typedef recognition in the lexical analyzer. This is
also needed for labels.  However, this simple change to the grammar
presented in the standard does not result in an LALR1 grammar. I found
the transformations required to get a grammar that yacc would accept
quite difficult to find and the result was not very elegant. So my
answer to the question "Or is it?" is NO!

   Ken Walker / Computer Science Dept / Univ of Arizona / Tucson, AZ 85721
   +1 602 621 2858  kwalker@Arizona.EDU   {uunet|allegra|noao}!arizona!kwalker
Technical Details
Message-ID: <9937@megaron.arizona.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!noao!arizona!kwalker
References: <5200040@m.cs.uiuc.edu> <12443@watdragon.waterloo.edu> <12778@watdragon.waterloo.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!noao!arizona!kwalker
From: kwalker@arizona.edu (Kenneth Walker)
Newsgroups: comp.lang.misc
Subject: Re: Language Design, or: is C's Grammar Context Free
Summary: ANSI Standard and typedefs
Keywords: BNF, Grammars, Silliness
Message-ID: <9937@megaron.arizona.edu>
Date: 29 Mar 89 03:55:48 GMT
References: <5200040@m.cs.uiuc.edu> <12443@watdragon.waterloo.edu> <12778@watdragon.waterloo.edu>
Organization: U of Arizona CS Dept, Tucson
Lines: 35