Various implementation of polish notation in ruby
The purpose of this project is just to have a simple working example of polish notation parser.
Currently two different implementation are available: handcraft parser and PEG with treetop
This is a toy project, it should be operationnal nonetheless
Both implementation supports: - Integer / Float - negative numbers - + - / * - parenthesis - Tolerant spacing
Treetop parser depends on treetop and specs on rpec 1.x+. To install them run:
HandcraftParser will not work under ruby 1.9 as it relies on sorted hash
#with rubygems or bundler initialized require 'treetop_polish_parser' TreetopPolishParser.new.calculate('* -4 / 2.0 4') => -2.0
or require 'handcraft_polish_parser'
HandcraftPolishParser.new.calculate('* -4 / 2.0 4') => -2.0
You have some useful spec to check whether everything is working fine for any implementation it should be rspec 1.x compatible. To run it:
$ rspec -f d spec/*_spec.rb
or for rspec 1.x
$ spec spec/*_spec.rb
Or run them independently:
$ ruby spec/treetop_parser_spec.rb