Jparsec is now ported to Ruby, with a way lighter syntax than Java.
The following is the ruby version of calculator:
As easy as that!
The above example directly calculates the result. What if we want to construct abstract syntax tree instead?
The first step is of course to create the abstract syntax tree classes. For example:
There's only one change to make in the parser code: change "integer.map(&To_i)" to "integer.map
Nothing else needs to be changed.
rparsec can be downloaded at http://rubyforge.org/frs/?group_id=2326
API document is available online
Created by benyu benyu
On Sun Oct 08 14:53:56 CDT 2006