An LALR(1) grammar for C is not much help
Sam Kendall
kendall at wjh12.UUCP
Sat May 5 04:34:47 AEST 1984
A correct LALR(1) grammar for C does not make writing a parser for C all
that much easier. There is a sort of a grammar in the reference manual;
one can fuss over it until it at least generates all legal C programs,
although it generates plenty of illegal ones, too. Unfortunately, the
difficulty in parsing C comes in (1) the kludges necessary to make a
lexical analyzer powerful enough to be the input for yacc (the lexical
analyzer needs to know which name space to look in, and there are worse
complications with typedef names) and in (2) the "semantic routines"
called from the grammar: the symbol table routines and the expression
legality checking, to name the most intricate. Determining what the
language is to begin with, by scrutinizing the reference manual, looking
at existing programs, and testing various compilers, is a problem as
difficult as actually making the parser correct. I am the main author of
bcc, a C runtime checker (which of course includes a parser); anyone who
has written a C compiler will tell the same story: making a grammar is
a trivial part of actually making a parser.
Sam Kendall {allegra,ihnp4,ima,amd70}!wjh12!kendall
Delft Consulting Corp. decvax!genrad!wjh12!kendall
More information about the Comp.lang.c
mailing list