The Wrong Stuff
Jonathan M Davis
jmdavisProg at gmx.com
Sat Sep 25 18:39:02 PDT 2010
On Saturday 25 September 2010 18:24:27 Simen kjaeraas wrote:
> Jonathan M Davis <jmdavisProg at gmx.com> wrote:
> > That could be the case - I'd have to look at the grammar or parser to be
> > sure -
> > but that would be a poor way to do it if you ever intended to have
> > user-defined
> > attributes. Normally, @ would be in the grammar as a separate symbol
> > indicating
> > that the symbol immediately followed was an identifier which was an
> > attribute.
> > It's quite possible, however, that @property is currently treated as a
> > single
> > symbol which is a keyword. I doubt that it will stay that way in the
> > long term
> > though, if it is the case.
>
> It appears I have not made my stance on this clear - in my mind, anything
> that is illegal to use as an identifier, but that is allowed to use in the
> language, is a keyword (that is roughly my definition, at least). I don't
> care whether the compiler uses this method or that to determine whether it
> is a keyword. Perhaps it would be better to use the term 'reserved word'
> to encompass both keywords and @tributes (the latter with the @-prefix
> included).
Well, I'm definitely looking at it from the point of view of the grammar and the
parser, and in theory at least, @ indicates than the identifier which immediately
follows is an attribute (so, technically, property would be the attribute, not
@property - @ just indicates that the intentifier which follows - in this case,
property - is an attribute). As such, they're not keywords. But obviously, you
can't use @property for something else in your code, so it is reserved in that
sense.
However, since you can't use @ in an identifier *anyway*, it's not like it's
really costing you anything. Object costs you more when it's not even a keyword
(it's just that it's a type which is always defined). By your thinking, Object
*would* be considered a keyword, but it isn't as far as the grammar and parser
are concerned.
And if we ever get user-defined attributes like Java does (we can only hope),
then what follows the @ could be of your own design, and it really won't work to
think about @property as a single entity any more than it works to think of int
x as a single entity. x is an entity which has been defined as type int by the
int, It's generally better to think of @property as property being an entity
which has been defined as an attribute by the @.
Now, given that D does not currently support user-defined attributes, and given
that there is not presently really any difference between type modifiers and
attributes (some just so happen to be one as opposed to the other), I can see
why you'd think of them like keywords. But being into parsers and grammars and
the like and having used attributes in other languages, I tend to be much more
exact in how I look at it.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list