31 lines
1.1 KiB
Rust
31 lines
1.1 KiB
Rust
use crate::errors::RunError;
|
|
|
|
pub fn expr(memory: &mut Vec<u16>, arg: &String) {
|
|
for code in arg.chars() {
|
|
match code {
|
|
'>' => memory.push(0),
|
|
'$' => { memory.pop(); },
|
|
':' => memory.push(*memory.last().expect(&format!("{}", RunError::MemoryEmpty))),
|
|
'\\' => {
|
|
let ax = memory.pop().expect(&format!("{}", RunError::MemoryEmpty));
|
|
let ax2 = memory.pop().expect(&format!("{}", RunError::MemoryEmpty));
|
|
|
|
memory.push(ax);
|
|
memory.push(ax2);
|
|
}
|
|
'+' => {
|
|
let ax = memory.pop().expect(&format!("{}", RunError::MemoryEmpty));
|
|
memory.push(ax + 1);
|
|
}
|
|
'-' => {
|
|
let ax = memory.pop().expect(&format!("{}", RunError::MemoryEmpty));
|
|
memory.push(ax - 1);
|
|
}
|
|
|
|
_ => {
|
|
eprintln!("{}", RunError::InvalidExpressionUnknownOperator(code.to_string()));
|
|
std::process::exit(2);
|
|
}
|
|
}
|
|
}
|
|
} |