Babel Programming Language

Home
Getting Started
Babel Operators
Babel Guts
Babel Examples
The Babel Blog

Contact Us

Babel on github
Babel at RosettaCode
Babel at Strange Loop 2013

Getting Started (Babel in Five Minutes)

You can download a Windows executable of Babel here (click the "Raw" button to begin the download). When you run the executable, Babel will start up in interactive mode. Type in the following Babel code at the prompt:

{ { iter itoa << " " << } iter times "\n" << } 20 times

Here's a brief explanation of what this program does:

<< prints to STDOUT
iter gets the current iteration of the current loop (countdown)
itoa converts "integer-to-ASCII", that is, number-to-string
times is a loop operator

On each iteration of the outer times loop, the iter operator returns a count value that is used for the inner times loop. So, the first row of numbers is 19 numbers wide (18 down to 0), the second row is 18 numbers wide, and so on down to zero, giving a single blank line.

The full list of implemented operators can be found by looking in the first column of src/opcode.h. Any operator that is not rsvd is currently implemented.

To quit interactive mode, type die.

Overview

Babel is an interpreted language. It is an untyped, stack-based, postfix language with support for arrays, lists and hashes (dictionaries). Babel 1.0 will support built-in crypto-based verification of code in order to enable safer remote code execution.

Babel Program Description Language (Bipedal)

There is partial support for Bipedal in Babel, as described below.

Lexicals

Bipedal is UTF-8 encoded - this means you can give your sections any name that can be encoded in UTF-8. You can easily alias the built-in operator names, as well.

A number can be a decimal integer or hexadecimal.

-42
32348
0x13

The limits are dependent on MWORD_SIZE (use the msize operator to get this) except for pnums which can be of arbitrary size.

A string is a set of characters wrapped in quotes:

"Lorem ipsum dolor sit amet"
'Lorem ipsum dolor sit amet'

Line comments in Bipedal are specified by double-dash:

-- This is a comment

An identifier is like any ordinary C-identifier.

Sections

(There are no sections in interactive mode)

Bipedal is organized at the top-level as a list of labeled sections. The top- level section is the section named main. You may define as many sections as you like, but only those sections that are referred to directly or indirectly by main will be compiled into the resulting babel code.

((main (foo))
(foo (bar))
(bar (foo)))

Leaf-arrays

A leaf-array is defined by enclosing a string or one or more numbers in square-brackets with the 'val' tag:

[val 1 1 2 3 5 8 13 0x15]
[val 101]
[val "Let me not to the marriage of true minds admit impediments"]

Interior-array

An interior-array is defined by enclosing one or more leaf-arrays, labels or interior arrays in square-brackets with the 'ptr' tag:

[ptr [val "achilles"] [val "tortoise"] ]

Lists

Lists are created with parentheses. A list in Babel means a linked-list in the Lisp-sense. The following are equivalent:

(1 2 3)
[ptr 1 [ptr 2 [ptr 3 nil]]]

You can verify this with the following code:

{ (1 2 3) [ptr 1 [ptr 2 [ptr 3 nil]]] == }

... which will evaluate to 0 (which means they are the same, see arcmp).

The nil element is distinct from that of Lisp in that Babel has no notion of an atomic and nil is just implemented as an entry in the symbol table - but you can take its car or cdr and you will always get nil again.

One final difference between Bipedal syntax and Lisp syntax is that Bipedal does not use the dot-notation. In Lisp, the following syntax

(1 2 . 3)

... expresses the same list as the following written in Bipedal:

(1 [ptr 2 3])

A code-list is created with curly-braces.

{ 2 3 + }
{ "Hello, " "world\n" . << }

Tagged-pointers

The tagged-pointer is the third basic sub-type alongside interior-arrays and leaf-arrays that together comprise the bstruct type in which all Babel data is stored. A tagged-pointer is created with the following syntax:

[tag "foo" bar]

This creates a tagged pointer named "foo" which points at bar.

Compiling Babel

Babel is written in C and will compile on any C99-compliant compiler. I am using MinGW and Babel compiles without any warnings with -Wall. If you have any questions about compiling Babel, please contact us.