On Wed, Aug 26, 2009 at 8:47 PM, Stewart Gordon<[email protected]> wrote: > Robert Fraser wrote: >> >> Stewart Gordon wrote: >>> >>> Have you written a compiler for a superset of C in which arbitrary >>> forward references are allowed? How did you do with overcoming the >>> difficulty that is C's context-sensitive grammar? >> >> C (minus preprocessor, of course) is only context-sensitive with regards >> to casts AFAIK. Since casts are always expressions, you can rewrite >> parenthesized expressions to casts (or vice versa) in a second pass but >> still allow forward references. > > <snip> > > Not quite. For example, is > > qwert * yuiop; > > a declaration of yuiop as a pointer to a qwert, or an instruction to > multiply qwert by yuiop but do nothing with the result?
It's grammatically ambiguous, but not semantically. No-op statements are illegal. Thus, it's perfectly fine to always parse this as a pointer decl, since the other possible parse tree is always semantically invalid.
