## Evaluate arithmetic infix operators

Discussion of Scheme and Racket
dsjoka
Posts: 14
Joined: Thu Feb 10, 2011 1:30 pm

### Evaluate arithmetic infix operators

I need to write a program with the following criteria:
Returns either a value or the word "ERROR"
Returns a value if it is called with a list that contains:
A single number, or`
An "ADD" ("+") command or "MULTIPLY" ("*") command in infix notation where the two operands must be recursively evaluated by MyEval.
My question is how do you take an expression that looks like: (1 + 2) and turn it into (+ 1 2) in the code?

Thanks.

dsjoka
Posts: 14
Joined: Thu Feb 10, 2011 1:30 pm

### Re: Evaluate arithmetic infix operators

Also for more complex cases like ( ((2+1) +3*4) * (5+6))

nuntius
Posts: 538
Joined: Sat Aug 09, 2008 10:44 am
Location: Newton, MA

### Re: Evaluate arithmetic infix operators

Here's the classic algorithm for parsing infix expressions.
http://en.wikipedia.org/wiki/Shunting-yard_algorithm

Exercise 2.58 in SICP takes a slightly different approach.