While Abstract Machine implemented in python.
Project description
while-machine
While Abstract Machine implemented in python.
While Machine is an abstract machine that is turing complete and can compute any partial recursive function. Find out more here https://en.wikipedia.org/wiki/Abstract_machine
Install
Run inside terminal:
python -m pip install while-machine
Usage
To execute a ram source file:
python -m while_machine <while source file> <integer input>
To import it in your script:
from while_machine import WhileMachine
data = 4
program = 'begin inc 0 inc 0 end'
wm = WhileMachine()
result = wm.compute(program, data)
print(result) # 2
How it works
A while machine has 21 registers numbered from 0, 1, 2..., the input is loaded on register 1 before the execution starts, the output is taken from register 0 when the execution ends.
Instructions:
A while machine supports only 4 basic instructions:
Increment register k by 1:
inc k
Decrement register k by 1:
dec k
Set register k to zero:
zero k
While register k is not zero, do the following command:
while k
Commands can be grouped with:
begin
...
...
end
Example
An example program that will double whatever input you give to the machine:
while 1
begin
inc 0
inc 0
dec 1
end
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for while_machine-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0fd7257f844f6facadafb8018f0faa1854114038db4ede46f28c5a8b54c70601 |
|
MD5 | aaef823da379922dae7a1a2dffe1eb17 |
|
BLAKE2b-256 | 6e0dd33b7f470283c7e9b76564973b1140151d435328b8235b95c94b74f7fdd0 |