On Jul 1, 2009, at 5:27 AM, Eduardo Cavazos wrote:

Below is a Scheme version of the shunting yard algorithm as explained on this page:

    http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm

Example:

    > (infix 3 + 4 * 5 - 6 ^ 7 + 8)
    (+ (- (+ 3 (* 4 5)) (^ 6 7)) 8)

Abdulaziz Ghuloum wrote:

A few questions:

1. You're not handing left/right associativity, right?

Eh... can you give an example? Or, does this help to clarify? :

    > (infix '(a + b - c))
    (- (+ a b) c)

2. Do you handle parenthesized subexpressions? (there seems to be a missing
   recursive call)

Not in the version I originally posted. This one handles subexpressions:

    http://proteus.freeshell.org/_shunting-yard-d.scm

For example:

    > (infix '(a + b - c * d / e = f))

    (= (- (+ a b) (/ (* c d) e)) f)

Ed

Reply via email to