Giter Site home page Giter Site logo

jameshinshelwood / registermachineinterpreter Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 0.0 74 KB

Register machine interpreter written in C

License: GNU General Public License v3.0

C 97.38% C++ 0.89% Makefile 1.73%
register-machine register-machine-interpreter register-programs packer turing registers computation-theory interpreter

registermachineinterpreter's Introduction

Register Machine Interpreter and Packer

Register machine interpreter written in C.
Register machines and packed integer form are implemented as described here.

Compiling

Can be compiled with make. You might have to change the compiler in Makefile.

Running

Interpreter

interpreter reads a program from stdin, and takes initial register values as arguments.

For example, cat add.r | ./interpreter 0 7 8, will run a register machine that computes R0=R1+R2=7+8.

Packer

packer [-p|-u] packs or unpacks a program from stdin and outputs the result. -p converts from a normal program to a packed integer. -u converts from a packed integer into a program.

For example, cat add.r | ./packer -p will convert the add program into an integer representation of it.
cat add.r | ./packer -p | ./packer -u | ./interpreter 0 81 129 will convert add to an integer and back again, then run the program.

Register Machine Programs

The syntax of register programs is from here. Thank you ๐Ÿ™‚

Each line of a file must be in one of the following formats:

  1. HALT will stop the program
  2. INC REGISTER NEXT_LABEL will increment REGISTER and jump to NEXT_LABEL
  3. DEC REGISTER LABEL_1 LABEL_2 will decrement REGISTER and jump to LABEL_1 if REGISTER is greater than zero, otherwise it will jump to LABEL_2

REGISTER, NEXT_LABEL, LABEL_1, and LABEL_2 must be nonnegative integers.

The first line of the file is L0 in the register machine, the second line is L1, and so on.

registermachineinterpreter's People

Contributors

jameshinshelwood avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.