Bare Bones Interpreter

Beware of the Turing tar-pit in which everything is possible but nothing of interest is easy.
Alan Perlis

News

20-FEB-2008: Release 0.4 makes identifiers case-insensitive. The README file now includes a summary of the language.
13-FEB-2008: Release 0.3 adds an optional optimizer, which significantly improves performance of one very common Bare Bones idiom.

Introduction

BareBones is an interpreter for the "Bare Bones" programming language defined in Chapter 11 of Computer Science: An Overview, 9th Edition, by J. Glenn Brookshear.

A brief summary of the Bare Bones language may be found here.

BareBones should be invoked from the command line with the name of the source file given as an argument:


        barebones prog1.bb

Optionally, additional command line arguments may be used to initialize variables:


        barebones X=37 Y=116 prog1.bb

This interpreter supports the optional "copy" statement, which can be viewed as a simple macro to copy one variable to another without clearing the first, though the use of an unnamed temporary variable.

One extension is added to the language as defined in the book. At the beginning of a Bare Bones source file, prior to the program proper, variables may be initialized to non-negative integer values:


        init X = 37;

By default, variables that are not initialized explicitly will be implicitly initialized to zero. If the "-u" option is given on the command line, this initialization is suppressed, and any reference to an uninitialized variable, other than in a clear statement, will result in a run time error.

Before the program is interpreted, the initial values of all variables will be printed to standard output. After successful completion of the interpreter, the final values will be printed.

The "-O" command line option enables optimization of the program. Currently only one type of optimization is performed. A common idiom in Bare Bones programs is to use a while loop to add one variable to another, clearing the first in the process. The optimizer will recognize this idiom and implement a direct solution, replacing the standerd iterative interpretation of the while loop.


Example Bare Bones Programs

Two simple sample Bare Bones programs are provided in the "examples" subdirectory. fibonacci.bb will compute the Nth number in the Fibonacci sequences. factorial.bb will compute the factorial of a (small) positive integer.

For example, to compute six factorial:


        barebones N=6 examples/factorial.bb

Translating Turing Machine Programs into Bare Bones Programs

The Bare Bones programming language is Turing-complete. It is possible to translate any Turing machine program into an equivalent Bare Bones program. In order to demonstrate how this may be accomplished, I have translated two simple two-state Turing machine "busy beaver" programs into equivalent Bare Bones programs. tm_busy_beaver_3.bb is a three-state busy beaver program that writes six consecutive ones to the tape, while tm_busy_beaver_4.bb is a four-state busy beaver program that writes thirteen nonconsecutive ones.


Download

Bare Bones is made available under the terms of the Free Software Foundation's General Public License, Version 3.

Source code is available for download.

Bare Bones development uses the Subversion revision control system. Instructions for access to the Subversion repository for Altogether are found at http://svn.brouhaha.com/, and there is a web interface to browse the repository at http://svn.brouhaha.com/viewvc/barebones.


Related web pages


Last updated January 24, 2009

Copyright 2008, 2009 Eric Smith

eric@brouhaha.com

hacker emblem
Best Viewed With Any Browser Valid HTML 4.01! Valid CSS!

check now

check now