From: George Ogata Date: 2005-04-29T20:13:05+09:00 Subject: Re: I need a formula parser Joel VanderWerf writes: > Daniel Berger wrote: >> However, I still do not have a formula parser. John's module uses >> Parse::RecDescent to parse formulas. I need something similar (or >> better). Preferably something generic that everyone can use and enjoy, >> but I'll take a more tailored parser if necessary. > > Might help... > > http://www.ruby-talk.org/cgi-bin/scat.rb/ruby/ruby-talk/110483 I have a more complete C parser at cast.rubyforge.org, if it's not too overkill for you. Here's a demo: irb(main):001:0> require 'cast/cast' => true irb(main):002:0> C::Expression.parse('sin(x / 180.0 * M_PI)') => Call expr: Variable name: "sin" args: - Multiply expr1: Divide expr1: Variable name: "x" expr2: FloatLiteral val: 180.0 expr2: Variable name: "M_PI"