Template instantiation syntax

Benji Smith dlanguage at benjismith.net
Sat Oct 11 13:42:58 PDT 2008


KennyTM~ wrote:
>> I hadn't seen this mentioned lately; C#, Java and now C++0x are able 
>> to work around the '> >' issue and allow '>>'.
>>
>> a) It works for C++0x so it can be made to work for D using the same 
>> rules. I also assume that C# and Java compilers use the same methods 
>> as C++0x to work around the ambiguities with the right-shift operator.

I sympathize, because I actually prefer the Foo<Bar> syntax for template 
declarations.

But it's not a question of it being *harder* to parse, or Walter being 
"lazy". The only way to resolve the ambiguity in the parser would be to 
do semantic analysis during the lexical phase.

I've worked with a few open-source Java parsers, and ">>" is always 
recognized as a right-shift operator during tokenization. But then, if 
the statement doesn't make any sense, the semantic analyzer can rewrite 
the token stream. (I don't know how Sun does it, but I imagine it's 
something like that.)

As much as I like the angle-bracket template syntax, I think it's a good 
choice to get rid of that ambiguity.

One of the best parts of the D language design is that it's lexically 
unambiguous, so tokenization, syntactic analysis, and semantic analysis 
can be completely separate from one another.

--benji



More information about the Digitalmars-d mailing list