I’m trying to make a DSL for defining algebraic equations. Given that this is the order of infix operation precedence in scala:
(all letters) | ^ & = ! < > : + - * / % (all other special characters)
This doesn’t work well for algebraic equations as:
^is defined with lower precedence than
*. So using it for exponentiation results in a lot of parenthesis.
- If I wanted to use
**for exponentiation, it seems to have equal precedence to
*. Again resulting in a lot of parenthesis.
- I also tried
/\but this seems like it also has the same precedence as
This kind of destroys the elegance of having a DSL, if you have to parenthesize everything.
So is there anything I can do to get around this infix operator precedence?
If nothing can be done in current scala; I did have one idea for a future version. Perhaps making it so an operator of the same symbol repeated would have higher precedence than one of the same symbol repeated fewer times.
** would have higher precedence than
*, for example.
Please let me know what you think. Thanks.