3 ms·
Better Operator Precedence
- jhallenworld 5y agoSo this old problem is all about the ambiguities that arise when squishing a two dimensional structure- a tree into a one dimensional space- a line of FORTRAN (and all subsequent programming languages). But there are better options, and they are showing up, in of all things, calculators. Modern calculators allow equations to be entered in typesetting notation. For example, you enter a fraction bar key, then it allows you to enter the numerator, hit arrow key, then enter denominator. The fraction bar grows to accommodate the arguments. For complex expressions, this method requires fewer keystrokes than FORTRAN because it saves on parenthesis. It's also much easier to read. (It's interesting to think about the resulting one-dimensional representation- the sequence of keystrokes: Bar <numerator> Down <denominator> Right). Programming languages should make use of this. There are many operators, so your editor could allow you to draw some kind of visual representation of a tree right in the code. Operator precedence as a thing is then gone, and the visual representation makes the equation completely unambiguous. We can argue about the visual representation- it could be a tree with branches, boxes within boxes, vertical and horizontal bars..
- alexandrerond 5y agoIt's confusing until you use parentheses.