Herb Sutter briefly discusses D during interview
Jonathan M Davis
jmdavisProg at gmx.com
Wed Jun 8 09:16:25 PDT 2011
On 2011-06-08 08:57, 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.
Sight correction (I was in too much of a hurry when I typed that). The parsing
is done left-to-right just like the lexing/scanning is (it has to be).
However, the processing of the AST is effectively done outward from the
variable name. That is, the semantic analysis of the type is done outward from
the variable name and thus left-to-right. So, as far as the compiler getting
any meaning out of the type and figuring out what to do with it goes, it reads
right-to-left, _not_ left-to-right. And if you try and read it like a compiler
does - e.g. pointer to pointer to int, not int pointer pointer - then you'll
end up reading it right-to-left too.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list