Various polish notation parser implementation in ruby (Handcraft and PEG with treetop)
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
spec
.gitignore
Gemfile
README.mdown
handcraft_polish_parser.rb
polish.treetop
treetop_polish_parser.rb

README.mdown

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

Features

Both implementation supports: - Integer / Float - negative numbers - + - / * - parenthesis - Tolerant spacing

Depencies

Treetop parser depends on treetop and specs on rpec 1.x+. To install them run:

bundle install

HandcraftParser will not work under ruby 1.9 as it relies on sorted hash

Usage

#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

Specs

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