On Thu, 06 Aug 2009 15:10:27 -0700, Jarrett Billingsley <[email protected]> wrote:

On Thu, Aug 6, 2009 at 6:02 PM, Robert Jacques<[email protected]> wrote:

int a = 5 / 2; // compiler knows to use integer division

No, it doesn't. (i.e. Welcome to the limitations of a context-free grammar)
The right hand of the expression has to be evaluated before the left, or
otherwise function overloads, etc, don't work, so there's no way for the
compiler to know the type of the expected result when 5/2 is evaluated.

Uh, no.  This has literally nothing to do with the grammar.  What
happens in this line would be determined in the semantic phase, not
parsing.

I used the term context-free as the expression 5/2 must be evaluated free of its context: i.e. 'int a =' or 'real b ='. I apologise if this is an over generalization of the term (it's been too long since my algorithm's class) But the rest of my comment is valid. This came up before while looking at how 'long = int + int' should be evaluated with regard to overflow. Walter explained that currently in DMD, 'int+int' or in this case '5/2' gets evaluated before the assignment statement, so it doesn't know/can't use the type information of the assignment.

As I said polysemous values fixes this, but they are rather computationally expensive to support.

Reply via email to