Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
November 03, 2004 Context dependent keywords | ||||
---|---|---|---|---|
| ||||
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/ |
November 03, 2004 Re: Context dependent keywords | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lionello Lunesu | 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/ > > |
November 04, 2004 Re: Context dependent keywords | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | 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. |
November 04, 2004 Re: Context dependent keywords | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lionello Lunesu | 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
|
November 04, 2004 Re: Context dependent keywords | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lionello Lunesu | "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++. |
November 05, 2004 Re: Context dependent keywords | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lionello Lunesu | 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/ > |
November 05, 2004 Re: Context dependent keywords | ||||
---|---|---|---|---|
| ||||
Posted in reply to Thomas Kuehne | > 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.
|
Copyright © 1999-2021 by the D Language Foundation