Skip to content

Commit

Permalink
optimize BooleanExpression parser
Browse files Browse the repository at this point in the history
  • Loading branch information
zao111222333 committed Apr 3, 2024
1 parent 9736ee6 commit 0b79165
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 445 deletions.
27 changes: 3 additions & 24 deletions src/expression/boolean_expression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,15 @@
mod latch_ff;
pub use latch_ff::{FFBank, Latch, LatchBank, LatchFF, FF};
pub mod logic;
use std::{
borrow::Borrow,
collections::{HashSet, VecDeque},
str::FromStr,
};
use std::{borrow::Borrow, collections::HashSet, str::FromStr};

use biodivine_lib_bdd::{
boolean_expression::BooleanExpression as Expr, Bdd, BddVariableSetBuilder,
};

mod parser;
use itertools::Itertools;
use parser::{BoolExprErr, Token};
use parser::BoolExprErr;

lazy_static! {
static ref UNKNOWN: Box<Expr> = Box::new(Expr::Variable("_unknown_".to_owned()));
Expand Down Expand Up @@ -49,6 +45,7 @@ fn condition(cond: Expr, then_value: Expr, else_value: Expr) -> Expr {
);
expr
}

#[inline]
fn condition_box(cond: Box<Expr>, then_value: Box<Expr>, else_value: Box<Expr>) -> Expr {
// let box_cond = Box::new(cond);
Expand Down Expand Up @@ -161,7 +158,6 @@ impl std::hash::Hash for IdBooleanExpression {
}

impl From<BooleanExpression> for IdBooleanExpression {
// type Error = BoolExprErr;
#[inline]
fn from(value: BooleanExpression) -> Self {
let mut builder = BddVariableSetBuilder::new();
Expand All @@ -172,10 +168,6 @@ impl From<BooleanExpression> for IdBooleanExpression {
let variables = builder.build();
let bdd = variables.eval_expression(&value.expr);
Self { expr: value.expr, bdd }
// match variables.eval_expression(&value.expr) {
// Some(bdd) => Ok(Self { expr: value.expr, bdd }),
// None => Err(BoolExprErr::NoIdea(1)),
// }
}
}

Expand All @@ -188,19 +180,6 @@ impl FromStr for IdBooleanExpression {
}
}

impl FromStr for BooleanExpression {
type Err = BoolExprErr;
#[inline]
fn from_str(s: &str) -> Result<Self, Self::Err> {
let mut tokens: VecDeque<Token> = match parser::token_vec(s) {
Ok((_, vec)) => vec.into_iter().collect(),
Err(_) => return Err(BoolExprErr::Nom),
};
let expr = parser::process_tokens(&mut tokens)?;
Ok(Self { expr })
}
}

impl std::fmt::Display for BooleanExpression {
#[inline]
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Expand Down
Loading

0 comments on commit 0b79165

Please sign in to comment.