* Alexandr Korljukov.
* Turing mashine.
* Instructions: s.q s.b s.c s.s s.r, where
* s.q - a current state,
* s.b - a symbol to observe,
* s.c - a symbol to write on a current position,
* s.s - a shift direction of shift ( '<' or '>' ) ,
* s.r - a next state,
* 'a' and 'z' - a start and end state.
$ENTRY Go {
= <Prout
* For testing:
*
*****************************************************
* tur_rv.mst
* Reversing of the bits.
* For example, '1122' ==> '622115'
*****************************************************
<Tur 'a'
* tape
( ()'1122' )
* |_________ pointer *
* Program:
('a11>a') ('a22>a') ('a 5<b') ('a$$>a')
('b12<b') ('b21<b') ('b 6>z') ('b$0<b')
>
/*
*****************************************************
* tur_br.mst
* Checking a bracket's structure .
* For example, '*()((*' ==> '0(RL*'
* For example, '*()()*' ==> '1()()'
*****************************************************
<Tur 'a'
* tape
* ( ()'*()((*' )
( ()'*()()*' )
* |_________ pointer *
* Program:
('a**>b')
('bLL>b') ('bRR>b') ('b((>b') ('b* <d') ('b)R<c')
('cLL<c') ('cRR<c') ('c(L>b') ('c*0>z')
('dL(<d') ('dR)<d') ('d(0>z') ('d*1>z')
>
*/
>;
}
Tur {
'z' ((e.1) e.2) e.3 = e.1 e.2;
s.q ((e.1) s.b e.2) e.3 = <Tur1
<Search s.q s.b e.3> ((e.1) s.b e.2) e.3>;
s.q ((e.1) ) e.3 = <Tur s.q ((e.1) ' ' ) e.3>;
}
Tur1 {
s.c '<' s.r (( ) s.b e.2) e.3 = <Tur s.r (( ) ' ' s.c e.2) e.3>;
s.c '<' s.r ((s.a e.1) s.b e.2) e.3 = <Tur s.r ((e.1) s.a s.c e.2) e.3>;
s.c '>' s.r (( e.1) s.b e.2) e.3 = <Tur s.r ((s.c e.1) e.2) e.3>;
}
* Looking for an instruction.
Search {
s.q s.b ( s.q '$' '$' s.s s.r ) e.2 = s.b s.s s.r;
s.q s.b ( s.q '$' s.c s.s s.r ) e.2 = s.c s.s s.r;
s.q s.b ( s.q s.b s.c s.s s.r ) e.2 = s.c s.s s.r;
s.q s.b ( e.1 ) e.2 = <Search s.q s.b e.2>;
* s.q s.b = '?<z' ;
}