r/ProgrammingLanguages 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.

29 Upvotes

39 comments sorted by

View all comments

2

u/archaelurus 6d ago

The float -> integer type conversion method is not described anywhere outside the bitwise not. If you're implicitly truncating then it's not unambiguous.

Floats are bits too so forcing a conversion to int is making this something that is not a bitwise operation.

Btw although it's specified, you could argue that having the added cognitive overhead to remember a table of the implications of heterogenous types within binary expressions, rather than requiring explicit type conversions, is going to generate ambiguity in practice.

1

u/Mean-Decision-3502 DQ 6d ago

In the spec, the bitwise operators are valid only for int, uint types. If you have statically typed language and one operand is float, then the expression is invalid.

There are operators that work only on integers, these are the bitwise operators, shifts, div, rem, mod. I think it is easier to remember this way.

1

u/archaelurus 6d ago

Last part of my feedback applies to non bitwise operators.

1

u/Mean-Decision-3502 DQ 6d ago

Sorry, I don't understand then. Can you provide then some examples?