1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use crate::{
states::{State, States},
turing::{Move, Tape, Tapes},
Symbolic,
};
pub trait Scope<S: Symbolic> {
fn new(index: usize, state: State<States>, tape: Tape<S>) -> Self;
fn build(tape: Tapes<S>) -> Self
where
Self: Sized,
{
match tape {
Tapes::Normal(t) => Self::new(0, Default::default(), t),
Tapes::Standard(t) => Self::new(t.len() - 1, Default::default(), t),
}
}
fn insert(&mut self, elem: S);
fn position(&self) -> usize;
fn set_position(&mut self, index: usize);
fn set_state(&mut self, state: State<States>);
fn set_symbol(&mut self, elem: S);
fn shift(&mut self, shift: Move, elem: S) {
let index = self.position();
match shift {
Move::Left if self.position() == 0 => {
self.insert(elem);
}
Move::Left => {
self.set_position(index - 1);
}
Move::Right => {
self.set_position(index + 1);
if self.position() == self.tape().len() {
self.insert(elem);
}
}
Move::Stay => {}
}
}
fn state(&self) -> &State<States>;
fn scope(&self) -> &S {
self.tape()
.get(self.position())
.expect("Index is out of bounds...")
}
fn tape(&self) -> &Tape<S>;
}