aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
blob: 5f42b10e9cc48254579bbd3b24b91a72c9785768 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
pub mod complex;
pub mod context;
pub mod expression;
pub mod function;
pub mod operation;
pub mod string;
pub mod commonsense;
pub mod expression_function;

use std::collections::HashMap;

use complex::Complex;
use context::Context;
use expression::Expression;
use function::Function;
use operation::Operation;
use expression_function::ExpressionFunction;

fn main() {
    let func = ExpressionFunction::from_string("f(x) = x^2".to_string());

    let expr = "f(4 + 3i)";

    let ctx: Context = Context::new()
        .with_operations(commonsense_operations!{})
        .with_functions(commonsense_functions!{func.name() => func})
        .with_variables(commonsense_variables!{});

    let value = Expression::from_string(expr);
    match value.evaluate(&ctx) {
        Ok(res) => println!("{} = {}", expr, res),
        Err(err) => println!("Error: {}", err),
    }
}