Context-Free Grammars? What about arrays?

Ary Manzana ary at esperanto.org.ar
Fri Feb 11 05:56:36 PST 2011


On 2/11/11 6:03 AM, %u wrote:
> Hi,
>
> I think I'm having a little trouble understanding what's meant by context-free
> grammar. I've read that D is context-free, but is it really? What about an
> expression like:
>
> int[U] s;
>
> ? You can't tell -- without looking at the context -- whether U is a data type
> or a number, and so because associative arrays and regular arrays are
> syntactically different elements of the language, the syntax of D is tied in
> with its semantics, just like in C++.
>
> So is D really context-free? Or am I misunderstanding the meaning of the term?
>
> Thanks!

That will always parse to an associative array. Then in the semantic 
pass, if U is a constant expression that turns out to be an integer it 
is reinterpreted as a static array.

Take a look: 
https://github.com/D-Programming-Language/dmd/blob/master/src/mtype.c#L3924


More information about the Digitalmars-d-learn mailing list