Herb Sutter briefly discusses D during interview

Timon Gehr timon.gehr at gmx.ch
Wed Jun 8 09:16:52 PDT 2011


Jonathan M Davis wrote:
> On 2011-06-08 08:38, Timon Gehr wrote:
> > Jonathan M Davis wrote:
> > > ...
> > > No, people don't normally look at declarations such as
> > >
> > > int* a;
> > >
> > > as being right to left. But from the compiler's perspective, they are.
> > > The
> > >
> > > compiler doesn't look at the type of a as being an int pointer. It looks
> > > at it as being a pointer to an int. The * comes first and then the int.
> > > [snip.]
> >
> > It is more convenient for the compiler to read the declaration left to
> > right to construct the type. (just like for people)
>
> I'm sorry, but no. Yes, the compiler lexes/scans the code left-to-right, but
> in terms of how the type gets deciphered when parsing and using the resulting
> abstract syntax tree, the compiler is effectively processing the type outward
> from the variable, which almost always means right-to-left. The compiler has
> no concept of stuff like int pointer or int pointer pointer. It knows about
> pointer to int and pointer to pointer to int. And when you start looking at it
> that way, it's clearly right-to-left. The compiler is _not_ looking at it the
> way that a human normally does.
>
> - Jonathan M Davis

I'm sorry but yes. You are free to lay out your AST in any way you may please, but
when the compiler has to parse and build a type involving pointers, it will
proceed left-to-right. (and naturally so)

Walter Bright wrote:
> Type *Parser::parseBasicType2(Type *t)
> {
>     //printf("parseBasicType2()\n");
>     while (1)
>     {
>         switch (token.value)
>         {
>             case TOKmul:
>                 t = new TypePointer(t);
>                 nextToken();
>                 continue;
>         ....
>         }
>     ...
>     }

Of course, afterwards the compiler reasons from right to left. But parsing left to
right _is_ more convenient.


Timon




More information about the Digitalmars-d mailing list