n3tael d6e290f916
обновление 1.0.5
* стек теперь не бесконечный. задать можно через аргумент cli (максимум 65535, дефолт: 256)
2024-02-07 23:38:04 +02:00

34 lines
950 B
Rust

use crate::{errors::RunError, stack::StackVec};
pub fn expr(memory: &mut StackVec, arg: String) {
for code in arg.chars() {
match code {
'>' => memory.push(0),
'$' => { memory.pop(); },
':' => {
let data = memory.last().clone();
memory.push(data);
},
'\\' => {
let ax = memory.pop();
let ax2 = memory.pop();
memory.push(ax);
memory.push(ax2);
}
'+' => {
let ax = memory.pop();
memory.push(ax + 1);
}
'-' => {
let ax = memory.pop();
memory.push(ax - 1);
}
_ => {
eprintln!("{}", RunError::InvalidExpressionUnknownOperator(code.to_string()));
std::process::exit(2);
}
}
}
}