Skip to content

FilippoRanza/fractran

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fractran

A FRACTRAN language interpreter

Introduction

FRACTRAN is a Turing-complete esoteric programming language invented by John Conway in 1987. For more information check Wikipedia page and the original paper.

Installation

fractran should be compiled and installed using cargo. In this Section I assume that the reader has basic knowledge about git and the usage of command line environment.

To compile fractran clone this repository and then build the binary using:.

cargo build --release

The executable should be in the target/release directory.

Otherwise you can directly compile and install fractran by running:

cargo install --git https://github.com/FilippoRanza/fractran

In this case cargo will automatically move the executable into the default installation directory.

If you are on Unix remember to strip the executable. Go to the directory containing the fractran executable and run:

strip fractran

Usage

fractran takes its input source code from file given as command line argument. Running a FRACTRAN program with fractran is very simple, just call:

fractran your-src.fractran

You can always read the help:

fractran --help

Language

A FRACTRAN program is an ordered list of fractions and an initial value. fractran expects a file written as:

init NUMBER
list FRACTION_LIST

Where FRACTION_LIST is:

FRACTION_LIST := FRACTION FRACTION_LIST | FRACTION

And FRACTION is:

FRACTION := NUMBER NUMBER | NUMBER / NUMBER

The first NUMBER is the numerator, the second is the denominator.

NUMBER is an positive integer number (internally a 128 bit unsigned number).

It is possible to use C style single line and multi line comments.

Example

The following code implements the multiplication.

/*
    FRACTRAN multiplication.
*/
init 72 // 72 = 2³ + 3²
list 
    455 33
    11 13
    1 11
    3 7
    11 2
    1 3

More examples can be found in the examples directory.

Releases

No releases published

Packages

No packages published

Languages