aboutsummaryrefslogtreecommitdiff
path: root/example/turing/turing.cc
diff options
context:
space:
mode:
authorAdrian Kummerlaender2015-02-23 19:03:16 +0100
committerAdrian Kummerlaender2015-02-23 19:03:16 +0100
commit0dde43edac6817c3f0a237d25c2054c0ee75926c (patch)
tree037d04fd230f5aa613b6e8b3030e93973f5566b9 /example/turing/turing.cc
parent41b63eff7f76e6574ef238f821dad0212a619c2a (diff)
downloadTypeAsValue-0dde43edac6817c3f0a237d25c2054c0ee75926c.tar
TypeAsValue-0dde43edac6817c3f0a237d25c2054c0ee75926c.tar.gz
TypeAsValue-0dde43edac6817c3f0a237d25c2054c0ee75926c.tar.bz2
TypeAsValue-0dde43edac6817c3f0a237d25c2054c0ee75926c.tar.lz
TypeAsValue-0dde43edac6817c3f0a237d25c2054c0ee75926c.tar.xz
TypeAsValue-0dde43edac6817c3f0a237d25c2054c0ee75926c.tar.zst
TypeAsValue-0dde43edac6817c3f0a237d25c2054c0ee75926c.zip
Added binary incrementer state table to Turing machine example
* reintroduced `BLANK` as the _BLANK_ symbol * fixed implicit tape expansion in `tape::readSymbol`
Diffstat (limited to 'example/turing/turing.cc')
-rw-r--r--example/turing/turing.cc33
1 files changed, 31 insertions, 2 deletions
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::Char<'C'>, 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<tav::Size<0>, BLANK, BLANK, tav::Size<1>, tav::Char<'L'>>,
+ tav::List<tav::Size<0>, tav::Boolean<false>, tav::Boolean<false>, tav::Size<0>, tav::Char<'R'>>,
+ tav::List<tav::Size<0>, tav::Boolean<true>, tav::Boolean<true>, tav::Size<0>, tav::Char<'R'>>,
+ tav::List<tav::Size<1>, BLANK, tav::Boolean<true>, tav::Size<2>, tav::Char<'R'>>,
+ tav::List<tav::Size<1>, tav::Boolean<false>, tav::Boolean<true>, tav::Size<2>, tav::Char<'L'>>,
+ tav::List<tav::Size<1>, tav::Boolean<true>, tav::Boolean<false>, tav::Size<1>, tav::Char<'L'>>,
+ tav::List<tav::Size<2>, BLANK, BLANK, void, tav::Char<'L'>>,
+ tav::List<tav::Size<2>, tav::Boolean<false>, tav::Boolean<false>, tav::Size<2>, tav::Char<'R'>>,
+ tav::List<tav::Size<2>, tav::Boolean<true>, tav::Boolean<true>, 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<bool, 1, 0, 1, 0, 1, 0>;
+
+ printStates<
+ binary_increment_tape,
+ machine::run<
+ binary_increment,
+ tav::Size<0>,
+ binary_increment_tape,
+ tav::Size<0>
+ >
+ >("3. Binary Increment");
}