https://github.com/jrosen081/mathparser
A Swift library to parse mathematical expressions into Decimal values
https://github.com/jrosen081/mathparser
mathematics parser swift
Last synced: 6 months ago
JSON representation
A Swift library to parse mathematical expressions into Decimal values
- Host: GitHub
- URL: https://github.com/jrosen081/mathparser
- Owner: jrosen081
- License: mit
- Created: 2019-04-25T15:38:44.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-05-30T18:34:05.000Z (over 6 years ago)
- Last Synced: 2025-07-10T18:09:22.650Z (7 months ago)
- Topics: mathematics, parser, swift
- Language: Swift
- Size: 52.7 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MathParser
[](https://travis-ci.org/jrosen081/MathParser)
[](https://cocoapods.org/pods/MathParser)
[](https://cocoapods.org/pods/MathParser)
[](https://cocoapods.org/pods/MathParser)
## What it is:
MathParser is a library written in swift that will allow a user to parse a String.
## What you can do with it:
* Addition
* Subtraction
* Multiplication
* Division
* Exponents
* Overload the operators.
## How to use:
Here is an example of how to use the library.
``` swift
let expr = Parser.parse(string: "1 + 2") // Will return an expression that can be evaluated.
let exprValue = expr?.evaluate() // Evaluates the expression (will be 3 in this example)
```
To overload operators (this can be done if wanted):
```swift
Operators.addOp = ">"
let ans = Parser.parse(string: "1 > 2")?.evaluate() // This will evaluate to 3 with the new operator
```
## Public methods:
* Parser.parse
* This returns an Optional Expression. This will return nil if the String is unparseable.
* Expression.evaluate
* This returns an Optional Decimal. This will only return nil if there is a division by 0.
## Example
To run the example project, clone the repo, and run `pod install` from the Example directory first.
## Requirements
## Installation
MathParser is available through [CocoaPods](https://cocoapods.org). To install
it, simply add the following line to your Podfile:
```ruby
pod 'MathParser'
```
## Author
jrosen081, jrosen081@gmail.com
## License
MathParser is available under the MIT license. See the LICENSE file for more info.