www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Context dependent keywords

reply "Lionello Lunesu" <lionello.lunesu crystalinter.remove.com> writes:
The other day I was reading about VC++ .NET 2005 and read this:

[...] Context-sensitive keywords are only keywords when used in certain 
contexts, and spaced keywords are only keywords when used in combination 
with other keywords. For example, the __property keyword from Managed 
Extensions is replaced with the property keyword. [...] This doesn't prevent 
you from using "property" as the name of a variable in your code. A token 
parsed as "property" is only treated as a keyword when in the context of 
declaring a property on a type. [...]

(from 
http://msdn.microsoft.com/msdnmag/issues/04/05/visualc2005/default.aspx )

I think this would be REALLY cool for D. You can do "int switch;" or 
whatever, since there's really only one way to parse this. In fact, if the D 
parser is parsing one term at a time, there's no way it'll even consider 
that "switch" to be the switch-statement.

IDE's would have to get a little smarter in coloring words in the code 
editor though.

-- 
Lionello.

-- Get the CACert root certificate (and a personal one) at 
http://cacert.org/ 
Nov 03 2004
next sibling parent reply "Walter" <newshound digitalmars.com> writes:
Unfortunately, that would make things harder for tools to lex and parse.

"Lionello Lunesu" <lionello.lunesu crystalinter.remove.com> wrote in message
news:cmb0ga$27s0$1 digitaldaemon.com...
 The other day I was reading about VC++ .NET 2005 and read this:

 [...] Context-sensitive keywords are only keywords when used in certain
 contexts, and spaced keywords are only keywords when used in combination
 with other keywords. For example, the __property keyword from Managed
 Extensions is replaced with the property keyword. [...] This doesn't
prevent
 you from using "property" as the name of a variable in your code. A token
 parsed as "property" is only treated as a keyword when in the context of
 declaring a property on a type. [...]

 (from
 http://msdn.microsoft.com/msdnmag/issues/04/05/visualc2005/default.aspx )

 I think this would be REALLY cool for D. You can do "int switch;" or
 whatever, since there's really only one way to parse this. In fact, if the
D
 parser is parsing one term at a time, there's no way it'll even consider
 that "switch" to be the switch-statement.

 IDE's would have to get a little smarter in coloring words in the code
 editor though.

 -- 
 Lionello.

 -- Get the CACert root certificate (and a personal one) at
 http://cacert.org/
Nov 03 2004
parent reply "Lionello Lunesu" <lionello.lunesu crystalinter.remove.com> writes:
Hi..

"Walter" <newshound digitalmars.com> wrote in message 
news:cmbofq$10sr$1 digitaldaemon.com...

 Unfortunately, that would make things harder for tools to lex and parse.
How often do you consider the complexity of parsing by other tools when designing D? It would be a pity if tools hinder the development of the language / compiler. Futhermore, wouldn't those tools be able to use parsing-library built from part of the D code? L.
Nov 03 2004
parent "Walter" <newshound digitalmars.com> writes:
"Lionello Lunesu" <lionello.lunesu crystalinter.remove.com> wrote in message
news:cmcmeq$2ur7$1 digitaldaemon.com...
 Hi..

 "Walter" <newshound digitalmars.com> wrote in message
 news:cmbofq$10sr$1 digitaldaemon.com...

 Unfortunately, that would make things harder for tools to lex and parse.
How often do you consider the complexity of parsing by other tools when designing D?
Often. C++ has been held back, and a number of other languages have leaped forward, due the relative difficulties of third party tools being able to parse it.
 It would be a pity if tools hinder the development of the language /
 compiler.
The language needs to be very friendly to tool development.
 Futhermore, wouldn't those tools be able to use parsing-library built from
 part of the D code?
Yes, but that's only if the tool is written in C++.
Nov 04 2004
prev sibling next sibling parent reply Thomas Kuehne <thomas-dloop kuehne.cn> writes:
Lionello Lunesu schrieb am Mittwoch, 3. November 2004 17:18:
 The other day I was reading about VC++ .NET 2005 and read this:
 
 [...] Context-sensitive keywords are only keywords when used in certain
 contexts, and spaced keywords are only keywords when used in combination
 with other keywords. For example, the __property keyword from Managed
 Extensions is replaced with the property keyword. [...] This doesn't
 prevent you from using "property" as the name of a variable in your code.
 A token parsed as "property" is only treated as a keyword when in the
 context of declaring a property on a type. [...]
 
 (from
 http://msdn.microsoft.com/msdnmag/issues/04/05/visualc2005/default.aspx )
 
 I think this would be REALLY cool for D. You can do "int switch;" or
 whatever, since there's really only one way to parse this. In fact, if the
 D parser is parsing one term at a time, there's no way it'll even consider
 that "switch" to be the switch-statement.
What would D gain by doing so? The problem is that you can come up with ambigious code where you'd like to use a variable with a contex-sensetive name but will clash with the keyword meaning of the name. e.g. a struct/class member named sizeof will result in great pain ;) Thomas
Nov 04 2004
parent "Lionello Lunesu" <lionello.lunesu crystalinter.remove.com> writes:
 The problem is that you can come up with ambigious code where you'd like 
 to
 use a variable with a contex-sensetive name but will clash with the 
 keyword
 meaning of the name.
 e.g. a struct/class member named sizeof will result in great pain ;)
Not all keywords should be usable on all places, of course. But, like in my example, there often is no ambiguity. OK, what if we forget the built-in keywords, but look at user types/methods instead. int doit(); alias int doit; I bet this is not allowed, but the first "doit" is part of the variable/function namespace, whereas the second "doit" is part of the type namespace. "doit x;" can only be a variable of type "doit". whereas (C) "void* x = doit;" or "doit();" refers/calls the function. I agree, now, that the reserved language keywords should remain reserved. "int int; int=2;" is not ambigious, but just confusing :-) Lio.
Nov 05 2004
prev sibling parent "D Language" <uframer sina100.com.cn> writes:
i don't think it's a good idea. it brings disaster rather than convenience.
"Lionello Lunesu" <lionello.lunesu crystalinter.remove.com>
写入消息新闻:cmb0ga$27s0$1 digitaldaemon.com...
 The other day I was reading about VC++ .NET 2005 and read this:

 [...] Context-sensitive keywords are only keywords when used in certain 
 contexts, and spaced keywords are only keywords when used in combination 
 with other keywords. For example, the __property keyword from Managed 
 Extensions is replaced with the property keyword. [...] This doesn't 
 prevent you from using "property" as the name of a variable in your code. 
 A token parsed as "property" is only treated as a keyword when in the 
 context of declaring a property on a type. [...]

 (from 
 http://msdn.microsoft.com/msdnmag/issues/04/05/visualc2005/default.aspx )

 I think this would be REALLY cool for D. You can do "int switch;" or 
 whatever, since there's really only one way to parse this. In fact, if the 
 D parser is parsing one term at a time, there's no way it'll even consider 
 that "switch" to be the switch-statement.

 IDE's would have to get a little smarter in coloring words in the code 
 editor though.

 -- 
 Lionello.

 -- Get the CACert root certificate (and a personal one) at 
 http://cacert.org/
 
Nov 05 2004