Ambiguity in C

16 points by icefox


edk-

I don't understand why this article insists on referring to context-sensitivity as “ambiguity”. C's syntax can't be expressed in BNF, but it's not ambiguous, although the BNF given in the standard of course is.

If you’ve ever written a parser for C, you’ll know the most annoying part is the ambiguities.

I can't really agree with that. The solution is inelegant but it's also easy, self-contained, and doesn't interact multiplicatively with other things.

OTOH a nice, user-friendly compiler wants to do things like trace tokens back through preprocessor expansions, issue context-sensitive warnings, keep looking for more errors after the first one, and so on. You can add one or two things like that to a basic compiler without major problems, but if you add all the modern conveniences you will quickly end up with a spaghetti nightmare mess where everything knows about everything else, changing any single thing takes weeks, and the whole thing will come crashing down if someone sneezes near it.

That is annoying. I'm not sure if it's specific to C though.