On Jul 5, 2009, at 10:54 AM, Eduardo Cavazos wrote:
OK, so... I'm trying to keep the core algorithm really simple. When I
added unary '-' it seemed to make it quite a bit more complicated to
deal with this overloading. So for now, I keep it simple by using
'neg' as the unary negate.
Abdulaziz Ghuloum wrote:
So, ..., it appears that I need an infix->prefix converter for a project
that I'm working on, but the infix expression may contain any C operator
(including unary *and* binary - and +). I cannot pre-convert the unary
versions to use different names.
Do you have the code for handling those? (or, are you willing to add them?)
Where is the latest version of your library/code?
OK... I needed some fancier features. I also added what you asked for.
;; Juxtaposition indicates multiplication
(infix '(2 x y))
(* (* 2 x) y)
;; Unary operators
(infix '(- x))
(- x)
(infix '(a + - b))
(+ a (- b))
(infix '(a - - - b))
(- a (- (- b)))
;; If it's followed by parentheses, it's a function
(infix '(sin (x)))
(sin x)
(infix '(abc (x)))
(abc x)
;; Show off some special features used together
(infix '( - 2 sin(x) cos(x) y ))
(- (* (* (* 2 (sin x)) (cos x)) y))
Latest version:
http://proteus.freeshell.org/_shunting-yard-terms-e.scm
It's *alot* messier. ;-) However, some things got nicer. You no longer
have to explicitly list symbols which you want to act as unary operators.
Ed