YACC grammar for C

Vik Lall vik at mentor.cc.purdue.edu
Sat Oct 28 01:02:27 AEST 1989


In article <6368 at arcturus>, evil at arcturus.UUCP (Wade Guthrie) writes:

> I have seen requests for a YACC grammar for C (which I never thought I'd need
> until now), but I can't find any reference to it in our archives.  Does anyone
> have one?

look at :

	uunet.uu.net:~ftp/net.sources/ansi.c.grammar.Z

Here is the README from that shar..

enjoy..

The files in this directory contain the ANSI C grammar from the April 30, 1985
draft of the proposed standard. This copy also incorporates all bug fixes I
have seen since the last two postings. With a little work this grammar can
be made to parse the C that most of us know and love (sort of).

There is one bug fix to the grammar that is in this posting. On line 295
of gram.y it previously read declaration_specifiers instead of
type_specifier_list as it does now. I believe the folks at the ANSI committee
made a mistake since if you replace the line with what the original read
you will end up with 16 shift/reduce errors and 2 reduce/reduce errors
(the good ones). As it is, it only has 1 shift/reduce error that occurs
on the if/else construct. YACC creates the correct parser and I don't want
to ugly my grammar up.

Anyway, all cumquats unite and generate this sucker. Then just sit and play
with it. Remember, the grammar accepts things like

	"Hello, world"++;
	--1.23456;
	*'a'

but this is not a bug, but simply a shuffling of the checking into the
semantic analysis. If you want to hack it up to do lvalue and rvalue
checking, I'm sure the ANSI committee would be glad to have your changes.
Don't send'em to me though. I don't want'em. Wear this in good health.

Jeff Lee
gatech!jeff	jeff at gatech	jeff%gatech.CSNet at CSNet-Relay.ARPA

---
Vik Lall 				vik at mentor.cc.purdue.edu 
Purdue University Computing Center	lall at purccvm                            



More information about the Comp.lang.c mailing list