Project

methic

0.0
No commit activity in last 3 years
No release in over 3 years
Simple arithmetic implemented by Treetop.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 5.0
>= 0

Runtime

 Project Readme

Methic Build Status

Simple arithmetic implemented via Treetop.

Heavily based on treetop arithmetic example.

Installation

Add this line to your application's Gemfile:

gem 'methic'

And then execute:

$ bundle

Or install it yourself as:

$ gem install methic

Usage

parser = MethicParser.new

parser.parse('0').eval #=> 0
parser.parse('1').eval #=> 1
parser.parse('123').eval #=> 123

parser.parse('x').eval('x' => 0) #=> 0
parser.parse('x').eval('x' => 3) #=> 3
parser.parse('y').eval('y' => 10) #=> 10

parser.parse('x + 5').eval('x' => 5) #=> 10
parser.parse('x - 5').eval('x' => 5) #=> 0
parser.parse('x * 2').eval('x' => 3) #=> 6
parser.parse('x / 2').eval('x' => 6) #=> 3

parser.parse('1 + 2 * 3 + 4').eval #=> 11
parser.parse('5 - 2 - 1').eval #=> 2

parser.parse('(5 + x) * (10 - y)').eval('x' => 0, 'y' => 5) #=> 25

parser.parse('4 == 4').eval #=> true
parser.parse('4 == 3').eval #=> false

Contributing

  1. Fork it ( https://github.com/zizkovrb/methic/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request