LL(1) C grammar

Henry Spencer henry at zoo.toronto.edu
Wed Jun 19 01:57:43 AEST 1991


In article <91-06-021 at comp.compilers> jos at and.nl (J. Horsmeier) writes:
>anyone out there having (knowing of) a LL(1) grammar for `C'...

Parsing C using LL(1) is tricky.  (Actually the same is true of LR(1)...)
C is pretty intractable without some special-purpose fudges in the scanner,
which don't fit cleanly into a normal LL(1)/LR(1) skeleton.  Although I
would not call it definitely impossible, I would be very surprised to see
a workable LL(1) grammar for C without such help.

If you want an example of why, consider the following legal C program:

	typedef int t;

	main(){
		t i = sizeof(t);

	t:	i = (t)(i+sizeof(i));
	}

C is *almost* LL(1), but typedefs, labels, casts, and sizeof make for some
interesting parsing problems.  It's doable, but it tends to require ad-hoc
mechanisms rather than just machine-processed grammars.
-- 
"We're thinking about upgrading from    | Henry Spencer @ U of Toronto Zoology
SunOS 4.1.1 to SunOS 3.5."              |  henry at zoo.toronto.edu  utzoo!henry



More information about the Comp.lang.c mailing list