2025-05-14 11:42:19 +02:00
|
|
|
mod rsprocess;
|
|
|
|
|
use lalrpop_util::lalrpop_mod;
|
2025-06-18 11:28:04 +02:00
|
|
|
use rsprocess::translator::WithTranslator;
|
|
|
|
|
// use std::rc::Rc;
|
2025-05-19 00:10:23 +02:00
|
|
|
// use std::io;
|
2025-05-14 11:42:19 +02:00
|
|
|
|
|
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
|
lalrpop_mod!(grammar, "/rsprocess/grammar.rs");
|
|
|
|
|
|
2025-06-16 14:46:04 +02:00
|
|
|
let mut translator = rsprocess::translator::Translator::new();
|
|
|
|
|
|
2025-05-19 00:10:23 +02:00
|
|
|
// let mut buffer = String::new();
|
|
|
|
|
// let i = io::stdin();
|
|
|
|
|
// i.read_line(&mut buffer).expect("Can't read stdin");
|
2025-05-14 11:42:19 +02:00
|
|
|
|
2025-06-16 14:46:04 +02:00
|
|
|
// let result = grammar::SetParser::new().parse(&mut translator, &buffer).unwrap();
|
2025-05-19 00:10:23 +02:00
|
|
|
|
|
|
|
|
|
2025-05-21 00:03:36 +02:00
|
|
|
// -------------------------------------------------------------------------
|
2025-06-16 14:46:04 +02:00
|
|
|
// let reactants = grammar::SetParser::new().parse(&mut translator, "{a}").unwrap();
|
|
|
|
|
// let inihibitors = grammar::SetParser::new().parse(&mut translator, "{c}").unwrap();
|
|
|
|
|
// let products = grammar::SetParser::new().parse(&mut translator, "{a,c}").unwrap();
|
2025-05-19 00:10:23 +02:00
|
|
|
|
2025-05-21 00:03:36 +02:00
|
|
|
// let process1 = rsprocess::structure::RSreaction::from(reactants, inihibitors, products);
|
2025-05-19 00:10:23 +02:00
|
|
|
|
2025-06-16 14:46:04 +02:00
|
|
|
// let reactants = grammar::SetParser::new().parse(&mut translator, "{b}").unwrap();
|
|
|
|
|
// let inihibitors = grammar::SetParser::new().parse(&mut translator, "{c}").unwrap();
|
|
|
|
|
// let products = grammar::SetParser::new().parse(&mut translator, "{b,c}").unwrap();
|
2025-05-19 00:10:23 +02:00
|
|
|
|
2025-05-21 00:03:36 +02:00
|
|
|
// let process2 = rsprocess::structure::RSreaction::from(reactants, inihibitors, products);
|
2025-05-19 00:10:23 +02:00
|
|
|
|
2025-06-16 14:46:04 +02:00
|
|
|
// let current_state = grammar::SetParser::new().parse(&mut translator, "{b}").unwrap();
|
2025-05-19 00:10:23 +02:00
|
|
|
|
2025-05-21 00:03:36 +02:00
|
|
|
// println!("{:?}", rsprocess::classical::compute_all(¤t_state, vec![&process1, &process2]));
|
2025-05-14 11:42:19 +02:00
|
|
|
|
2025-05-21 00:03:36 +02:00
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
2025-06-16 14:46:04 +02:00
|
|
|
// let env = grammar::EnvironmentParser::new().parse(&mut translator, "[x = {a}.{b}.x , y = ({a,c}.y + {b,c}.y)]").unwrap();
|
|
|
|
|
// let process = grammar::ContextParser::new().parse(&mut translator, "[({a}.nil + x + y)]").unwrap();
|
2025-05-21 00:03:36 +02:00
|
|
|
|
2025-06-12 16:23:39 +02:00
|
|
|
// println!("{:?}", rsprocess::transitions::unfold(&env, &process));
|
|
|
|
|
|
|
|
|
|
// println!("--------------------");
|
|
|
|
|
|
|
|
|
|
// println!("{:?}", env);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
// allTransitions(sys([],[a,b],[],[react([a],[c],[a]),react([b],[d],[b])]) , Moves).
|
|
|
|
|
|
2025-06-16 14:46:04 +02:00
|
|
|
// let env = grammar::EnvironmentParser::new().parse(&mut translator, "[]").unwrap();
|
|
|
|
|
// let process = grammar::ContextParser::new().parse(&mut translator, "[]").unwrap();
|
2025-06-12 16:23:39 +02:00
|
|
|
|
2025-06-16 14:46:04 +02:00
|
|
|
// let sys = rsprocess::structure::RSsystem::from(Rc::new(*env),
|
2025-06-18 11:28:04 +02:00
|
|
|
// rsprocess::structure::RSset::from(vec![translator.encode("a"),
|
|
|
|
|
// translator.encode("b")]),
|
2025-06-12 16:23:39 +02:00
|
|
|
// *process,
|
2025-06-16 14:46:04 +02:00
|
|
|
// Rc::new(vec![
|
2025-06-12 16:23:39 +02:00
|
|
|
// rsprocess::structure::RSreaction::from(
|
2025-06-18 11:28:04 +02:00
|
|
|
// rsprocess::structure::RSset::from(vec![translator.encode("a")]),
|
|
|
|
|
// rsprocess::structure::RSset::from(vec![translator.encode("c")]),
|
|
|
|
|
// rsprocess::structure::RSset::from(vec![translator.encode("a")])
|
2025-06-12 16:23:39 +02:00
|
|
|
// ),
|
|
|
|
|
// rsprocess::structure::RSreaction::from(
|
2025-06-18 11:28:04 +02:00
|
|
|
// rsprocess::structure::RSset::from(vec![translator.encode("b")]),
|
|
|
|
|
// rsprocess::structure::RSset::from(vec![translator.encode("d")]),
|
|
|
|
|
// rsprocess::structure::RSset::from(vec![translator.encode("b")])
|
2025-06-12 16:23:39 +02:00
|
|
|
// )
|
2025-06-16 14:46:04 +02:00
|
|
|
// ]));
|
2025-06-12 16:23:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// println!("all_transitions: {:?}", rsprocess::transitions::all_transitions(&sys));
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
// parse_ctx("[({a}.nil + {b}.nil)]",Ks) , allTransitions(sys([],[],Ks,[react([a],[c],[a]),react([b],[d],[b])]),Moves).
|
2025-06-16 14:46:04 +02:00
|
|
|
// let env = grammar::EnvironmentParser::new().parse(&mut translator, "[]").unwrap();
|
|
|
|
|
// let process = grammar::ContextParser::new().parse(&mut translator, "[({a}.nil + {b}.nil)]").unwrap();
|
2025-06-12 19:16:32 +02:00
|
|
|
|
2025-06-16 14:46:04 +02:00
|
|
|
// let sys = rsprocess::structure::RSsystem::from(Rc::new(*env),
|
2025-06-12 19:16:32 +02:00
|
|
|
// rsprocess::structure::RSset::from(vec![]),
|
|
|
|
|
// *process,
|
2025-06-16 14:46:04 +02:00
|
|
|
// Rc::new(vec![
|
2025-06-12 19:16:32 +02:00
|
|
|
// rsprocess::structure::RSreaction::from(
|
2025-06-18 11:28:04 +02:00
|
|
|
// rsprocess::structure::RSset::from(vec![translator.encode("a")]),
|
|
|
|
|
// rsprocess::structure::RSset::from(vec![translator.encode("c")]),
|
|
|
|
|
// rsprocess::structure::RSset::from(vec![translator.encode("a")])
|
2025-06-12 19:16:32 +02:00
|
|
|
// ),
|
|
|
|
|
// rsprocess::structure::RSreaction::from(
|
2025-06-18 11:28:04 +02:00
|
|
|
// rsprocess::structure::RSset::from(vec![translator.encode("b")]),
|
|
|
|
|
// rsprocess::structure::RSset::from(vec![translator.encode("d")]),
|
|
|
|
|
// rsprocess::structure::RSset::from(vec![translator.encode("b")])
|
2025-06-12 19:16:32 +02:00
|
|
|
// )
|
2025-06-16 14:46:04 +02:00
|
|
|
// ]));
|
2025-06-12 19:16:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// println!("all_transitions: {:?}", rsprocess::transitions::all_transitions(&sys));
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
// parse_ctx("[({a}.nil + {b}.nil),({c}.nil + {d}.nil)]",Ks) , allTransitions(sys([],[],Ks,[react([a],[c],[a]),react([b],[d],[b])]),Moves).
|
2025-06-16 16:35:54 +02:00
|
|
|
// let env = grammar::EnvironmentParser::new().parse(&mut translator, "[]").unwrap();
|
|
|
|
|
// let process = grammar::ContextParser::new().parse(&mut translator, "[({a}.nil + {b}.nil),({c}.nil + {d}.nil)]").unwrap();
|
|
|
|
|
|
|
|
|
|
// let sys = rsprocess::structure::RSsystem::from(Rc::new(*env),
|
|
|
|
|
// rsprocess::structure::RSset::from(vec![]),
|
|
|
|
|
// *process,
|
|
|
|
|
// Rc::new(vec![
|
|
|
|
|
// rsprocess::structure::RSreaction::from(
|
2025-06-18 11:28:04 +02:00
|
|
|
// rsprocess::structure::RSset::from(vec![translator.encode("a")]),
|
|
|
|
|
// rsprocess::structure::RSset::from(vec![translator.encode("c")]),
|
|
|
|
|
// rsprocess::structure::RSset::from(vec![translator.encode("a")])
|
2025-06-16 16:35:54 +02:00
|
|
|
// ),
|
|
|
|
|
// rsprocess::structure::RSreaction::from(
|
2025-06-18 11:28:04 +02:00
|
|
|
// rsprocess::structure::RSset::from(vec![translator.encode("b")]),
|
|
|
|
|
// rsprocess::structure::RSset::from(vec![translator.encode("d")]),
|
|
|
|
|
// rsprocess::structure::RSset::from(vec![translator.encode("b")])
|
2025-06-16 16:35:54 +02:00
|
|
|
// )
|
|
|
|
|
// ]));
|
|
|
|
|
|
|
|
|
|
// let it = rsprocess::transitions::iterator_transitions(&sys)?;
|
|
|
|
|
|
|
|
|
|
// for (n, i) in it.into_iter().enumerate() {
|
|
|
|
|
// println!("next i - {n}: {:?}", i);
|
|
|
|
|
// println!("--------------------");
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
2025-06-18 11:28:04 +02:00
|
|
|
// let env = grammar::EnvironmentParser::new().parse(&mut translator, "[]").unwrap();
|
|
|
|
|
// let process = grammar::ContextParser::new().parse(&mut translator, "[({a}.nil + {b}.nil),({c}.nil + {d}.nil)]").unwrap();
|
|
|
|
|
|
|
|
|
|
// let sys = rsprocess::structure::RSsystem::from(Rc::new(*env),
|
|
|
|
|
// rsprocess::structure::RSset::from(vec![]),
|
|
|
|
|
// *process,
|
|
|
|
|
// Rc::new(vec![
|
|
|
|
|
// rsprocess::structure::RSreaction::from(
|
|
|
|
|
// rsprocess::structure::RSset::from(vec![translator.encode("a")]),
|
|
|
|
|
// rsprocess::structure::RSset::from(vec![translator.encode("c")]),
|
|
|
|
|
// rsprocess::structure::RSset::from(vec![translator.encode("a")])
|
|
|
|
|
// ),
|
|
|
|
|
// rsprocess::structure::RSreaction::from(
|
|
|
|
|
// rsprocess::structure::RSset::from(vec![translator.encode("b")]),
|
|
|
|
|
// rsprocess::structure::RSset::from(vec![translator.encode("d")]),
|
|
|
|
|
// rsprocess::structure::RSset::from(vec![translator.encode("b")])
|
|
|
|
|
// )
|
|
|
|
|
// ]));
|
|
|
|
|
// println!("{:?}", rsprocess::transitions::run_separated(&sys));
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
let tmp = rsprocess::structure::RSreaction::from(
|
|
|
|
|
rsprocess::structure::RSset::from(vec![translator.encode("a"), translator.encode("c")]),
|
|
|
|
|
rsprocess::structure::RSset::from(vec![translator.encode("c")]),
|
|
|
|
|
rsprocess::structure::RSset::from(vec![translator.encode("a")])
|
|
|
|
|
);
|
|
|
|
|
println!("{}", WithTranslator::from_RSreaction(&translator, &tmp));
|
2025-05-14 11:42:19 +02:00
|
|
|
Ok(())
|
|
|
|
|
}
|