[net.lang.c] Grammar for C

glenm@mako.UUCP (Glen McCluskey) (04/29/85)

Various people have asked about the availability
of a grammar for C.  The book "A C Reference Manual"
by Harbison & Steele (Prentice-Hall) contains a
complete LALR(1) grammar for the language.

	Glen McCluskey
	..tektronix!mako!glenm

dont@tekig1.UUCP (Don Taylor) (05/01/85)

There are a handful of typo's in the lalr(1) grammar in appendix c of
"A C Reference Manual" by Harbison and Steele (Prentice-Hall).  A letter
to them resulted in a prompt reply from Mr. Harbison, and I quote
------------

     -Change all occurances of "..._ctype>" to "..._type>".

     -Remove definitions of "<008>" and "<key_dcltr>"; they are not needed.

     -"<decl or stmt>" should be "<decl_or_stmt>".

In addition, if you have the first printing of the book, the production

     <cast_exp> ::= ( <typename_declaration> ) <prefix_exp>
should be
     <cast_exp> ::= ( <typename_declaration> ) <cast_exp>

You should also know that this grammar does not accomodate C's "old" form
of initializers and compound assignments.
------------
I hope this saves someone else a little confusion
Don Taylor
Tektronix Inc.

arnold@gatech.CSNET (Arnold Robbins) (05/01/85)

> Various people have asked about the availability
> of a grammar for C.  The book "A C Reference Manual"
> by Harbison & Steele (Prentice-Hall) contains a
> complete LALR(1) grammar for the language.
> 
> 	Glen McCluskey
> 	..tektronix!mako!glenm

Unfortunately, the grammar (along w/the rest of the book) is copyrighted
by the publisher, which will may be a problem should you wish to base
your C compiler on their grammar.  I know that Guy Steele is on the net
someplace; maybe he has something more authoritative to say about this.

On the other hand, the grammar given in the current draft(s) of the ANSI
C standard can be easily made LALR(1).  A YACC grammar based on the Nov 11
draft was posted awhile back by my office mate, Jeff Lee (gatech!jeff).
It is for the ANSI C, but could be easily made K&R C w/very little work.

Check your archives for net.sources for it, or if enough requests come
flooding in (as will probably happen), we'll repost it.
-- 
Arnold Robbins
CSNET:	arnold@gatech	ARPA:	arnold%gatech.csnet@csnet-relay.arpa
UUCP:	{ akgua, allegra, hplabs, ihnp4, seismo, ut-sally }!gatech!arnold

How come nobody likes good ideas when they don't come up with them?

oz@yetti.UUCP (Ozan Yigit) (05/02/85)

See the Sigplan Notices, Vol. 17 #8 Aug. 1982 for a full
BNF specification of C. (page 90)

Oz	(wizard of something or another, no doubt..)
	Usenet: [decvax | ihnp4 | allegra | linus]!utzoo!yetti!oz
	Bitnet: oz@yuleo | oz@yuyetti
---------
	Where you stand on an issue depends on where you sit.

arnold@gatech.CSNET (Arnold Robbins) (05/07/85)

> See the Sigplan Notices, Vol. 17 #8 Aug. 1982 for a full
> BNF specification of C. (page 90)
> 
> Oz	(wizard of something or another, no doubt..)
> 	Usenet: [decvax | ihnp4 | allegra | linus]!utzoo!yetti!oz
> 	Bitnet: oz@yuleo | oz@yuyetti
> ---------
> 	Where you stand on an issue depends on where you sit.

This grammar is very far from LALR(1).  While it can be made Yacc-able, it is
a lot of work.
-- 
Arnold Robbins
CSNET:	arnold@gatech	ARPA:	arnold%gatech.csnet@csnet-relay.arpa
UUCP:	{ akgua, allegra, hplabs, ihnp4, seismo, ut-sally }!gatech!arnold

How come nobody likes good ideas when they don't come up with them?