Recipe for converting infix algebraic expressions to Scheme
Expand abbreviations. For example,
7x actually means 7 * x,
3(x-2) actually means 3 * (x-2), etc.
Fully parenthesize the expression, even the outermost
operator, so that (a) it is completely unambiguous which operation
needs to happen next, and (b) every operator is surrounded by its own
private pair of parentheses. For example,
3 + x becomes (3 + x),
3 + 4 * 5 becomes (3 + (4 * 5)),
7 * x - (3+x)/(y+2) becomes ((7 * x) - ((3 + x) / (y + 2))),
Note that by the time you're done with this step, there should
be the same number of left parentheses, right parentheses, and
operators: in the last example, there are five operators (*, -, +, /, +)
so there must be five left parentheses and five right parentheses.
Move each operator left to just after its
left-parenthesis. For example,
(3 + x) becomes (+ 3 x),
(3 + (4 * 5)) becomes (+ 3 (* 4 5)),
((7 * x) - ((3 + x) / (y + 2))) becomes
(- (* 7 x) (/ (+ 3 x) (+ y 2))),
Be careful not to move anything except operators!
Tue Mar 5 10:46:53 EST 2002
Stephen Bloch / firstname.lastname@example.org