On Thu, Nov 19, 2009 at 1:26 PM, Walter Bright <newshou...@digitalmars.com> wrote: > aarti_pl wrote: >> >> I know that quite a few people here doesn't like to allow users to define >> their own operators, because it might obfuscate code. But it doesn't have to >> be like this. Someone here already mentioned here that it is not real >> problem for programs in C++. Good libraries don't abuse this functionality. > > The problem with user defined operators is: > > 1. User defined tokens - mixes up lexing with semantic analysis > > 2. User defined syntax - mixes up parsing with semantic analysis > > and then we're in C++ land :-( > > Unless such have a unique grammar that can be lexed and parsed: > > a :string: b > > where string is the user defined name, so you can do things like: > > a :^^: b > > and define your own pow operator. The problem with this approach is the > sheer ugliness of it.
You also have to wedge precedence in there somehow. Maybe instead of :string: you use +string+ or *string* and the first/last character tells the precedence. Oh wait, downs already has code that does this. The question, I think, is how to make it reasonably fast and less cumbersome to declare. Though I'm not sure it's really worth the effort. --bb