'C', is it's grammar context sensitive ?

Henry Spencer henry at zoo.toronto.edu
Fri Aug 24 14:09:32 AEST 1990


In article <1990Aug23.164905.10261 at NCoast.ORG> ramsey at NCoast.ORG (Cedric Ramsey) writes:
>... for declarations the grammar is context sensitive.
>Since the 'typedef-name' is an identifier is impossible to determine that
>it is a type defintion without looking at the context...

Correct.  C's grammar has not been truly context-free, in the usual sense,
since typedefs were added, over a decade ago.  This is Excedrin Headache
Number 3.14159 of writing a C parser.  The standard answer is to have
some sort of ugly feedback path between symbol table and scanner, so
that the scanner can distinguish typedef names from other identifiers
and tell the parser "this one's a typedef name".  You can't easily do
this with a pre-pass because typedefs obey the block-structured scope
rules:  you need nearly a full parse just to classify identifiers.
-- 
Committees do harm merely by existing. | Henry Spencer at U of Toronto Zoology
                       -Freeman Dyson  |  henry at zoo.toronto.edu   utzoo!henry



More information about the Comp.lang.c mailing list