From 0dde43edac6817c3f0a237d25c2054c0ee75926c Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Mon, 23 Feb 2015 19:03:16 +0100 Subject: Added binary incrementer state table to Turing machine example * reintroduced `BLANK` as the _BLANK_ symbol * fixed implicit tape expansion in `tape::readSymbol` --- example/turing/turing.cc | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'example/turing/turing.cc') diff --git a/example/turing/turing.cc b/example/turing/turing.cc index ab377e2..720697a 100644 --- a/example/turing/turing.cc +++ b/example/turing/turing.cc @@ -5,6 +5,8 @@ #include "src/machine.h" +using BLANK = machine::tape::BLANK; + // (define mirror (list (list 1 1 0 2 'R') [...])) using mirror = tav::List< // [state] [read] [write] [next state] [head movement] @@ -31,13 +33,27 @@ using busy_beaver = tav::List< tav::List, tav::Int<1>, tav::Int<1>, void, tav::Char<'N'> > >; +// (define binary_increment (list (list 0 '() '() 1 'L') [...])) +using binary_increment = tav::List< +// [state] [read] [write] [next state] [head movement] + tav::List, BLANK, BLANK, tav::Size<1>, tav::Char<'L'>>, + tav::List, tav::Boolean, tav::Boolean, tav::Size<0>, tav::Char<'R'>>, + tav::List, tav::Boolean, tav::Boolean, tav::Size<0>, tav::Char<'R'>>, + tav::List, BLANK, tav::Boolean, tav::Size<2>, tav::Char<'R'>>, + tav::List, tav::Boolean, tav::Boolean, tav::Size<2>, tav::Char<'L'>>, + tav::List, tav::Boolean, tav::Boolean, tav::Size<1>, tav::Char<'L'>>, + tav::List, BLANK, BLANK, void, tav::Char<'L'>>, + tav::List, tav::Boolean, tav::Boolean, tav::Size<2>, tav::Char<'R'>>, + tav::List, tav::Boolean, tav::Boolean, tav::Size<2>, tav::Char<'R'>> +>; + template < typename Initial, typename Final > void printStates(const std::string& name) { - const auto printField = [](const int x) { - std::cout << x << " "; + const auto printField = [](const auto x) { + std::cout << x << ' '; }; std::cout << name @@ -80,4 +96,17 @@ int main(int, char **) { tav::Size<6> > >("2. Busy Beaver"); + + // (define binary_increment_tape (list #t #f #t #f #t #f)) + using binary_increment_tape = tav::ListOfType; + + printStates< + binary_increment_tape, + machine::run< + binary_increment, + tav::Size<0>, + binary_increment_tape, + tav::Size<0> + > + >("3. Binary Increment"); } -- cgit v1.2.3