When a digit or '.' is typed and the cursor's position is...
- in a placeholder, populate the placeholder with a numeric expression.
- inside a number, insert the character into the number.
y * 4|.35 becomes y * 46.35
- in an infix binary operator or prefix operator and the next node is...
- a placeholder, populate the placeholder with a numeric expression.
w -|_ becomes w - 9
(-|_) becomes (-9)
- a number, append the character to the number.
z +|7 becomes x+17
(-|20) becomes (-120)
- a variable and the operator is...
- binary, insert a multiplication with a new number as the left child and the variable as the right child.
6 -|x becomes 6 - 2 * x
3 ^|a becomes 3 ^ (2 * a)
- prefix, replace the unary operator with a multiplication between the unary operator with a new number and the variable.
postfix operators: TBD
Note:
Should '.' be considered a binary operator? It would solve the issue of a numeric expression solely containing '.' being a legal expression, and potentially of it being inserted more than once into a single number. It would also create placeholders on either side.
When a digit or '.' is typed and the cursor's position is...
x + _|becomesx + 4y * 4|.35becomesy * 46.35w -|_becomesw - 9(-|_)becomes(-9)z +|7becomesx+17(-|20)becomes(-120)6 -|xbecomes6 - 2 * x3 ^|abecomes3 ^ (2 * a)(-|t)becomes(-4)*tpostfix operators: TBD
Note:
Should '.' be considered a binary operator? It would solve the issue of a numeric expression solely containing '.' being a legal expression, and potentially of it being inserted more than once into a single number. It would also create placeholders on either side.