C sintax

Michael Condict mnc at m10ux.UUCP
Wed Feb 3 05:47:47 AEST 1988


In <548 at gtx.com>, al at gtx.com (Alan Filipski) writes:
> I'll stick my neck out and say I don't think there ARE any syntactic
> ambiguities in C. (there are, of course, the semantic ones resulting
> from undefined order of evaluation).  The potential ambiguities such
> as the dangling else and those involving the comma operator are solved
> by fiat.
> 
> Are there any syntactic ambiguities K&R didn't resolve?
> 
>     ----------------------------------------------------------------------
>    | Alan Filipski, GTX Corp, 2501 W. Dunlap, Phoenix, Arizona 85021, USA |
>    | {ihnp4,cbosgd,decvax,hplabs,amdahl}!sun!sunburn!gtx!al (602)870-1696 |
>     ----------------------------------------------------------------------

Yes, there are, at least if you mean context-free ambiguities.  That is,
without a symbol table or other context-sensitive techniques, the following
is ambiguous in C:

	{ t (x); ... }

If ``typedef ... t;'' appeared previously then this is a declaration of a var
named x of type t, otherwise it is a call to a function t with argument x.
This is more than a theoretical problem, since it implies that any parser
for C must include a symbol table package.  Thus if you wish to provide a
black-box C parser module to be used in multiple applications, either each
application must agree to use the symbol table package embedded in the parser,
or the application must redundantly provide its own symbol table.  Neither
prospect is very appealing to me.
-- 
Michael Condict		{ihnp4|vax135|cuae2}!m10ux!mnc
AT&T Bell Labs		(201)582-5911    MH 3B-416
Murray Hill, NJ



More information about the Comp.lang.c mailing list