43 lines
840 B
Rust
43 lines
840 B
Rust
use std::{collections::HashMap, num::NonZeroUsize};
|
|
|
|
use crate::tape::{Tape, TapeSymbol};
|
|
|
|
#[derive(Default)]
|
|
struct TuringMachine {
|
|
state_table: HashMap<(MachineState, TapeSymbol), MachineAction>,
|
|
tape: Tape,
|
|
}
|
|
|
|
impl TuringMachine {
|
|
fn new() -> Self {
|
|
TuringMachine::default()
|
|
}
|
|
|
|
fn with_state_entries(
|
|
state_entries: impl Iterator<Item = (MachineState, TapeSymbol, MachineAction)>,
|
|
) -> Self {
|
|
let mut machine = TuringMachine::new();
|
|
for (state, symbol, action) in state_entries {
|
|
machine.state_table.insert((state, symbol), action);
|
|
}
|
|
machine
|
|
}
|
|
}
|
|
|
|
#[derive(Eq, Hash, PartialEq)]
|
|
enum MachineState {
|
|
Halt,
|
|
StateNumber(NonZeroUsize),
|
|
}
|
|
|
|
struct MachineAction {
|
|
tape_write: TapeSymbol,
|
|
movement: MachineMovement,
|
|
new_state: MachineState,
|
|
}
|
|
|
|
pub enum MachineMovement {
|
|
Left,
|
|
Right,
|
|
}
|