Implementing a Programming Language in D: Lexical Analysis

Ali Çehreli via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Mon Dec 28 21:57:34 PST 2015


On 12/28/2015 04:28 PM, Walter Bright wrote:

 > 
https://www.reddit.com/r/programming/comments/3ykko7/implementing_a_programming_language_in_d_lexical/

Although the author does not use many D idioms, I've just learned 
(re-learned?) anonymous enums from that code.

I've realized that with a nested anonymous enum, there is no need to 
(and no way of) mentioning the enum type inside a user-defined type. 
This can simplify the implementation:

struct S {
     enum { value }

     void foo() {
         // Look ma, no type:
         assert(value == 0);
     }
}

void main() {
     // Properly name-spaced outside of the struct:
     assert(S.value == 0);
}

As can be seen, the users of the struct still have to name-space the 
enum value as S.value. There is no need for an additional enum type for 
example like S.MyEnum.value.

Ali



More information about the Digitalmars-d-announce mailing list