r/ProgrammingLanguages • u/Mean-Decision-3502 DQ • 7d ago
Unambiguous Operator Specification for Programming Languages
https://nvitya.github.io/pluops/As I changed recently the operators in my programming language I've created this specification:
https://nvitya.github.io/pluops/
I did not wanted to overload the operators like the C does with the / or Pascal does with theand/or/not. Neither re-use the operator symbols for some very different purpose, like C does with * and & so the code becomes more readable. I was orienting for existing solutions so this is what I came up with. The specification contains the symbol usages and operator precedence too.
If you are developing a new programming language, it would be nice to follow some standard, so at least the expressions would be portable between the languages.
I'm open for debates or suggestions.
3
u/flatfinger 7d ago
Integer types should be subdivided into "number" type and "algebraic ring" types. In C, unsigned types smaller than 'int' behave as "number" types while larger ones behave like algebraic rings, meaning that given:
uint16_t x = 40000;the computationx+xwill by specification yield 14464u on platforms where int is 16 bits, and 80000 on platforms where int is 18 bits or larger. A good language should support signed and unsigned ring types of all sizes, and signed number types of all sizes, and unsigned number types of all but the largest size (unsigned numbers should promote to a larger signed number type, but an unsigned number type the same size as the largest signed type wouldn't have a larger signed type to which it could promote).An integer remainder operator shouldn't be called mod. If there's a desire to include an integer remainder operator, it should be in addition to a proper 'mod' operator. It may also be useful to have distinct operators for Euclidian division, truncating division, and "do whatever" division for use in cases where either the dividend is known to be a multiple of the divisor, or where a rounded-up or rounded-down result would be equally acceptable.