Last - but not least! - two DConf talks

Jacob Carlborg via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Sat Jul 18 07:20:25 PDT 2015


On 2015-07-18 11:43, "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm at gmx.net>" 
wrote:

> The AST for this statement would look something like:
>
> (DeclStatement type=(Keyword "auto") name=(Identifier "a")
> value=(AssignExpression exp=(VariableOrParenlessCall var=(Identifier
> "foo"))))
>
> This would probably be considerably harder for trailing delegates...

I think there are nine different ways a user could want write the code 
to call a method with a trailing delegate. Only two of them are ambiguous.

foo {
}

foo (a){ // ambiguous
}

foo (int a){
}

foo(a) { // ambiguous
}

foo(a) (b){
}

foo(a) (int b){
}

foo() (){
}

foo (){
}

foo() {
}

When it is ambiguous the compiler can always parse it as trailing 
delegate and store that in a variable in the call expression. The 
semantic analyze will then disambiguate the call. That would be similar 
to how my current implementation works like:

1. If the current expression is a call expression or an identifier
2. If the current token is an opening curly brace, parse an expression
3.1 If the current expression is a call expression, push the expression 
from step 2 to its argument list
3.2 If the current expression is an identifier, replace that with a call 
expression, go to 3.1

This could be extended to store the delegate expression in a new 
variable in the call expression instead.

-- 
/Jacob Carlborg


More information about the Digitalmars-d-announce mailing list