Skip to content

Commit

Permalink
Merge branch 'release/0.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanmarvens committed Jul 5, 2014
2 parents d78bc18 + 8fccfe9 commit af54744
Show file tree
Hide file tree
Showing 18 changed files with 669 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.a
*.bak
*.dSYM
*.o
*.sw*
*.test
*~
/.bin
10 changes: 10 additions & 0 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Godeps/Readme

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Godeps/_workspace/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Godeps/_workspace/src/github.com/codegangsta/cli
Submodule cli added at bb9189
11 changes: 11 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
* The MIT License (MIT).
*
* https://github.com/jonathanmarvens/turing-machine
*
* Copyright (c) 2014 Jonathan Barronville ([email protected])
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 changes: 26 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
##########
default: build
##########

build: deps lint test
gox -output=".bin/{{.OS}}-{{.Arch}}/turing-machine" -verbose

clean:
rm -fr ./.bin

deps:
godep go install -v -x ./...

errcheck:
errcheck github.com/jonathanmarvens/turing-machine

fmt:
gofmt -e -s -w .

lint: fmt errcheck

test: lint
# TODO(@jonathanmarvens): Add some damn tests to fix this.

.PHONY: default
.PHONY: build clean deps errcheck fmt lint test
66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Turing machinez tho.

This is a simple turing machine I created for an article I’ve been writing titled, “*Neurons, turing machines, & lambda abstractions: an interesting combo?*

## Setup.

There are 3 ways you can install this on your system in order to play with it.

-----

__(1) Download a pre-built binary.__

You should be able to grab a pre-built binary on the [__Releases__ page](https://github.com/jonathanmarvens/turing-machine/releases) (oh, the power of Go cross-compiling __:)__ … I’m looking at you, GCC).

-----

Assuming you have your [Go workspace](http://golang.org/doc/code.html) all set up, the following are your two other options.

-----

__(2) Using `go get`.__

```sh
go get -t -u github.com/jonathanmarvens/turing-machine
```

-----

__(3) Building from source.__

```sh
go get -t -u github.com/kisielk/errcheck github.com/mitchellh/gox github.com/tools/godep
git clone https://github.com/jonathanmarvens/turing-machine.git $GOPATH/src/github.com/jonathanmarvens/turing-machine
cd $GOPATH/src/github.com/jonathanmarvens/turing-machine
make
```

Now look in the __.bin/__ directory.

-----

## Usage.

Running `turing-machine help` should be helpful enough about the usage.

-----

Feel free to use the example *programs* in [__examples/__](https://github.com/jonathanmarvens/turing-machine/tree/master/examples).

```sh
# ./.bin/{OS}-{ARCH}/turing-machine --prog="./examples/n-plus-1.btm.json"
```

## Author.

__Jonathan Barronville__ < [__http://乔纳森.com__](http://乔纳森.com) > ( *[email protected]* )

## Acknowledgements.

Here’s a great document that includes a formal (mathematical) definition of a turing machine (from Cornell University’s CS department): [http://www.cs.cornell.edu/courses/cs4820/2012su/handouts/turingm.pdf](http://www.cs.cornell.edu/courses/cs4820/2012su/handouts/turingm.pdf) … I liked this document more compared to like 6 others I read (the math is clearer and pretty straightforward to follow, there are real examples, the author doesn’t make stupid assumptions about things __-.-__, *et cetera*), so I (loosely) modeled the turing machine around it. You should read it if you want a better mathematical understanding of turing machines! Please don’t rely on Wikipedia for a good understanding of turing machines.

Here’s a good document, which also includes a formal definition of a turing machine: [http://plato.stanford.edu/entries/turing-machine](http://plato.stanford.edu/entries/turing-machine) … although I didn’t particularly love this document, it’s pretty informative (you probably wanna read it first if you’re new to turing machines).

## License.

See [__LICENSE__](https://github.com/jonathanmarvens/turing-machine/blob/master/LICENSE).
23 changes: 23 additions & 0 deletions error/error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* The MIT License (MIT).
*
* https://github.com/jonathanmarvens/turing-machine
*
* Copyright (c) 2014 Jonathan Barronville ([email protected])
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package error

import (
"errors"
)

func New(msg string) error {
return errors.New("[github.com/jonathanmarvens/turing-machine]: " + msg)
}
128 changes: 128 additions & 0 deletions examples/binary-string-prepend-zero.tm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
{
"K": [
"l", "r0", "r1", "s"
],

"s": "s",

"Σ": [
"^", "$", "0", "1"
],

"x": [
"^", "0", "1", "0", "1", "1", "1", "0",
"$"
],

"δ": [
{
"map": {
"dir": "R",
"state": "r0",
"sym": "^"
},

"state": "s",
"sym": "^"
},

{
"map": {
"dir": "R",
"state": "r0",
"sym": "0"
},

"state": "r0",
"sym": "0"
},

{
"map": {
"dir": "R",
"state": "r1",
"sym": "0"
},

"state": "r0",
"sym": "1"
},

{
"map": {
"dir": "L",
"state": "l",
"sym": "0"
},

"state": "r0",
"sym": "$"
},

{
"map": {
"dir": "R",
"state": "r0",
"sym": "1"
},

"state": "r1",
"sym": "0"
},

{
"map": {
"dir": "R",
"state": "r1",
"sym": "1"
},

"state": "r1",
"sym": "1"
},

{
"map": {
"dir": "L",
"state": "l",
"sym": "1"
},

"state": "r1",
"sym": "$"
},

{
"map": {
"dir": "L",
"state": "l",
"sym": "0"
},

"state": "l",
"sym": "0"
},

{
"map": {
"dir": "L",
"state": "l",
"sym": "1"
},

"state": "l",
"sym": "1"
},

{
"map": {
"dir": "N",
"state": "@HALT",
"sym": "^"
},

"state": "l",
"sym": "^"
}
]
}
11 changes: 11 additions & 0 deletions examples/blank.tm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"K": [],

"s": "",

"Σ": [],

"x": [],

"δ": []
}
35 changes: 35 additions & 0 deletions machine/conf.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* The MIT License (MIT).
*
* https://github.com/jonathanmarvens/turing-machine
*
* Copyright (c) 2014 Jonathan Barronville ([email protected])
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package machine

type Conf struct {
currState State
currTapePos uint
}

func (self *Conf) MovTapePosLeft() {
if int(self.currTapePos) == 0 {
return
}
self.currTapePos--
}

func (self *Conf) MovTapePosRight() {
self.currTapePos++
}

func (self *Conf) SetCurrState(state State) {
self.currState = state
}
23 changes: 23 additions & 0 deletions machine/dir.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* The MIT License (MIT).
*
* https://github.com/jonathanmarvens/turing-machine
*
* Copyright (c) 2014 Jonathan Barronville ([email protected])
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package machine

type Dir string

const (
DirMovLeft Dir = "L"
DirMovRight Dir = "R"
DirStay Dir = "N"
)
Loading

0 comments on commit af54744

Please sign in to comment.