Crate positron[][src]

Expand description

positron - parse and execute boolean expressions

Examples

Basic Or Gate

use std::collections::HashMap;
use positron::{circuit::Circuit,gate::Gate};

// a + b
let gate =  Gate::Or(vec![Gate::Value("a".to_string()),Gate::Value("b".to_string())]);

let mut data = HashMap::new();
data.insert("a".to_string(),true);
data.insert("b".to_string(),true);

let circuit = Circuit {
    gate,
    data
};

assert_eq!(circuit.execute().unwrap(),true)

Parsing example

use std::{collections::HashMap,str::FromStr};
use positron::{circuit::Circuit,parser::Parsed};

let input = "(a+b).(a.b)";

let parsed = Parsed::from_str(input).unwrap();

assert!(parsed.variables.contains("a"));
assert!(parsed.variables.contains("b"));

let mut data = HashMap::new();
data.insert("a".to_string(),true);
data.insert("b".to_string(),true);

let circuit = Circuit {
    gate:parsed.root_gate,
    data
};

assert_eq!(circuit.execute().unwrap(),true)

Modules

Circuit Struct and impls

Error handling

Gate enum with impls

Expr parser

itertools.product with repeat

Generate truth table entries