D should disallow forward references
Stewart Gordon
smjg_1998 at yahoo.com
Wed Aug 26 17:47:51 PDT 2009
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?
OK, so since it's ambiguous only within a function, it won't have to
worry about running yet another pass to resolve the forward references
to yuiop. But FAIK there may be other cases that are more complicated
to deal with.
(That said, a D compiler probably needs more passes than this to resolve
all possible cases of conditional compilation that may rely on forward
referenced symbols. But then again, D is designed from the ground up
for multi-pass compilation.)
Stewart.
More information about the Digitalmars-d
mailing list