To view parent comment, click here.
To read all comments associated with this story, please click here.
Why impossible? But OK, it doesn't have to be infinitely flexible.
For example, in SML you can define any function that takes two arguments as infix and what precedence level it should have. It doesn't seem to support postfix though.
Is this possible in C++/Ruby or can you only redefine a given set of infix operators?
There should be a continuum from fixed syntax - overridable syntax - modifiable sytnax - extendable syntax - redefinable syntax - flexible syntax. So how for out on the right can you go? How much has been done already?
Postfix and infix should be trivial. Trinary a bit harder, but not that much. Syntax that wraps a block ([]"" and such) even harder.
C has macros to achieve a little syntax extension, but they are quite limited. But a preprocessor may be one way. Compiler plug-ins could be another way. In any case you shouldn't have to write a whole compiler just to get one language feature.





Member since:
2005-07-11
Implementing that is impossible in a compiled language, and I believe in any language that is parsed using current-day language parsers.
Since what you have in mind (as I understand it) involves modifying the syntax of the language in new ways, you would need a whole meta-language for modifying the base language, which involves another parser. Generally, I cannot see how this is worth the trouble. Not only will the parser be immensely complex (and thus bug-prone), it will also produce confusing and unreadable source-code (since every programmer can basically make up his own language conventions).
What defines a language is not the things you express with it, but the things you don't express with it.
- Simon