clojure-numerics / expresso

Clojure library for symbolic computation
312 stars 20 forks source link

parse-expression with parentheses #1

Closed szamuboy closed 10 years ago

szamuboy commented 10 years ago

Hi!

When I try to parse an expression that contains parentheses I get an error. For example:

(parse-expression "5 * (3 + 2)")
Parse error at line 1, column 5:
5 * (3 + 2)
    ^
Expected one of:
"["
#"[a-zA-Z]"
"-"
"+"
#"[1-9]"
#"[0-9]"
" "

I got this error with the 0.1.0 release.

mschuene commented 10 years ago

Oh yes, that's an whitespace issue in my parser. This works: (parse-expression "5*(3 + 2)") Will push a fix to master as soon as possible

thanks for the reporting

szamuboy commented 10 years ago

Thanks for the workaround! Keep up the good work with Expresso!

mschuene commented 10 years ago

pushed the fix to the current master branch. Can you confirm that it is working ? I could do a 0.2.0-SNAPSHOT release if you want to try it out from clojars.

szamuboy commented 10 years ago

I could compile expresso from the master branch and yes, this issue seems to be solved! That was really quick!

Thank you!

I'd like to provide an improvement idea as well. It would be great if parse-expression would accept equations as well. E.g.:

(parse-expression "10 * x = y + z")

Currently the parser cannot eat the = symbol.

mschuene commented 10 years ago

Great that it worked for you! Yes, until now the arithmetic operators are hard-wired in the parser and only a very limited set of operators are supported. Until the end of gsoc I want it to also accept any mathematical operator, so you can use it to convert between infix and s-exp form. I still have to work out how to handle precedence in this case. I think (high precedence top) '* ','/ '+,'- (other expressions like sin,cos ...) '= could work.