need examples to understand postfix expression grammar

Timon Gehr timon.gehr at gmx.ch
Sun Apr 16 19:07:21 UTC 2023


On 4/16/23 18:59, FabArd wrote:
> Hi,
> 
> I have trouble understanding these two rules of grammar :
> 
> PostfixExpression:
> - PostfixExpression ( ArgumentListopt )
> - TypeCtorsopt BasicType ( ArgumentListopt )
> 
> It seems to me that the first rule corresponds to a function call 
> expression.
> Is my analysis correct?
> ...

Yes.

> As for the second one, I don't understand how to use it.
> Can you give me examples of how to use it?

It's for conversion to the specified basic type (including qualified ones).

E.g., this works

---
void main(){
     auto x = immutable double(2);
     static assert(is(typeof(x)==immutable double));
     assert(x==2);
}
---

TBH I think it would be better if basic types were just expressions in 
their own right, but the parser currently is what it is, so atm this 
requires a specialized grammar rule.


More information about the Digitalmars-d mailing list