<commit_before># Rustyard ![alt text](https://travis-ci.org/simon-whitehead/rust-yard.svg?branch=master "master build status")

The [Shunting Yard algorithm](https://en.wikipedia.org/wiki/Shunting-yard_algorithm), implemented in Rust.

### The code

This is me experimenting with Rust (I love it so far). As such, the code quality may be questionable and not 100% idiomatic Rust.

### Using the code

You can instantiate a `ShuntingYard` instance with an expression and call its `calculate` method, which returns an `Result<f64, Vec<String>>`. An example would be:

```
extern crate rustyard;

fn main() {
    let yard = rustyard::ShuntingYard::new("2 + 4 * 3");

    // This prints "The result is: 14"
    println!("The result is: {}", yard.calculate().unwrap());
}
```

### Examples

The implementation accepts the 4 basic mathematical operators, the power operator and parenthesis. It also considers all input to be floating point. Some examples are below:

#### Basic addition:
```
Simon$ cargo run --example main "2 + 4"
Input is: 2 + 4
Lexer result: 2 + 4 
Shunting Yard result: 2 4 + 
Equation equals: 6
```

#### Floating point:
```
Simon$ cargo run --example main "1.75 * 2"<commit_msg>Updated README to show new usage of calculate method<commit_after># Rustyard ![alt text](https://travis-ci.org/simon-whitehead/rust-yard.svg?branch=master "master build status")

The [Shunting Yard algorithm](https://en.wikipedia.org/wiki/Shunting-yard_algorithm), implemented in Rust.

### The code

This is me experimenting with Rust (I love it so far). As such, the code quality may be questionable and not 100% idiomatic Rust.

### Using the code

You can instantiate a `ShuntingYard` instance with an expression and call its `calculate` method, which returns an `Result<f64, Vec<String>>`. An example would be:

```
extern crate rustyard;

fn main() {
    let yard = rustyard::ShuntingYard::new();

    // This prints "The result is: 14"
    println!("The result is: {}", yard.calculate("2 + 4 * 3").unwrap());
}
```

### Examples

The implementation accepts the 4 basic mathematical operators, the power operator and parenthesis. It also considers all input to be floating point. Some examples are below:

#### Basic addition:
```
Simon$ cargo run --example main "2 + 4"
Input is: 2 + 4
Lexer result: 2 + 4 
Shunting Yard result: 2 4 + 
Equation equals: 6
```

#### Floating point:
```
Simon$ cargo run --example main "1.75 * 2"
{'fraction_non_alphanumeric': 0.12597776862906546, 'fraction_numerical': 0.019761218608480857, 'mean_word_length': 4.294117647058823, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1808932', 'n_tokens_mistral': 784, 'n_tokens_neox': 707, 'n_words': 301}