← All projects

Tools

T.O.A.L.

The Totally Original Applicable Language: a plain-English programming language, with a compiler to JavaScript, built by a team of four. Variables are “make a with 55”, loops are “loop over”, and functions are “automations”. It has its own website and a syntax reference that sets every construct beside its JavaScript equivalent.

T.O.A.L. logo: a book with a computer monitor on the cover
Type
Team of 4
Category
Tools
Stack
JavaScript · Node.js · Ohm

Structure

How the parts fit together
Architecture diagram: T.O.A.L. source to Parser; Parser to Analyzer (parse tree); Analyzer to Optimizer (program graph); Optimizer to Generator; Generator to JavaScript

The compiler translates English-like source into JavaScript in four stages. The analyzer builds an object graph of the program and reports descriptive errors before any code is generated.

SheetStructure
ProjectT.O.A.L.
Parts6

Step through the compiler

A compiler turns code a person writes into code a computer can run. Follow one small T.O.A.L. program through the stages of its compiler. All of the output shown was produced by the real compiler.

Step 1 of 6

1 · Your program

A tiny program. A function doubles a number, and the program prints the result and says "Big" when it is more than 5.

This is a program written in T.O.A.L., a programming language that reads like plain English. A computer cannot run it directly, so a program called a compiler translates it first.

The compiler works in stages. Step through them to see what each one does to the program.

T.O.A.L. source
automate double(num: x) -> num {
    output x times 2;
}
make total with 3;
make result with double(total);
print result;
if result is greater than 5 {
    print "Big";
}

2 · Parse

First the compiler checks the sentence structure, the way you would check grammar. It splits each line into its parts, such as a name, a number or a math word, and arranges them into a tree.

If a line breaks the language’s rules, the compiler stops here and says so.

Simplified parse tree
Program
  Statement_autodec
    automate = automate
    id = double
    Params > ListOf > NonemptyListOf > Param
      type = num
      id = x
    type = num
    Block > Statement_output
      output = output
      VarVal > Exp > Exp_expression
        Exp > Term > Var > id = x
        operator = times
        Exp > Term > numeral = 2
  Statement_vardec
    make = make
    id = total
    VarVal > Exp > Term > numeral = 3
  Statement_vardec
    make = make
    id = result
    CallExp
      id = double
      Args > ListOf > NonemptyListOf > VarVal > Exp > Term > Var > id = total
  Statement_prnt
    print = print
    VarVal > Exp > Term > Var > id = result
  Statement_if
    if = if
    Boolean > BoolExp
      Exp > Term > Var > id = result
      boolop = is greater than
      Exp > Term > numeral = 5
    Block > Statement_prnt
      print = print
      VarVal > Word > strlit = "Big"

3 · Analyze

Next it checks that the program makes sense. Every name must be created before it is used. Numbers must be used as numbers, and each name is only usable in the part of the program (its scope) where it was created.

Mistakes become descriptive errors, such as a CallError or a TypeError. Use the toggle to see one the real compiler produced.

Checked program (analyzed tree)
Program
  AutomationDeclaration  double  outputs number
    params:
      x (variable, number)
    body:
      Output
        Expression  *  -> number
          left: x (variable, number)
          right: 2
  VariableDeclaration  total (number)
    value: 3
  VariableDeclaration  result (number)
    value: Call  double
      args:
        total (variable, number)
  Print
    argument: result (variable, number)
  If
    test: BooleanExpression  >  -> boolean
      left: result (variable, number)
      right: 5
    then:
      Print
        argument: "Big"
A mistake, caught by the real compiler
Line 5, col 25:
  4 | make total with 3;
> 5 | make result with double(total, 1);
                              ^~~~~~~~
  6 | print result;
CallError: 1 argument(s) required, but 2 passed.

Here the function is called with two inputs, but it only accepts one.

4 · Optimize

This stage is meant to tidy the program so it runs faster. In the current compiler it passes the program through unchanged.

That is why the tree below is the same as the one in the previous step.

Optimizer output: identical to the checked program
Program
  AutomationDeclaration  double  outputs number
    params:
      x (variable, number)
    body:
      Output
        Expression  *  -> number
          left: x (variable, number)
          right: 2
  VariableDeclaration  total (number)
    value: 3
  VariableDeclaration  result (number)
    value: Call  double
      args:
        total (variable, number)
  Print
    argument: result (variable, number)
  If
    test: BooleanExpression  >  -> boolean
      left: result (variable, number)
      right: 5
    then:
      Print
        argument: "Big"

5 · Generate

Now the compiler writes the program out in JavaScript, a language that web browsers and Node.js already know how to run.

Look at the names. Each one gets a number added to the end, such as price_1, so that two names can never clash.

Generated JavaScript (indented here to make it easier to read)
function double_2(x_1) {
  return x_1 * 2;
}
let total_3 = 3;
let result_4 = double_2(total_3);
console.log(result_4);
if (result_4 > 5) {
  console.log("Big");
}

6 · Run

Finally the JavaScript runs. This is what it printed to the console.

It was produced by running the generated code with Node.js.

Console output
6
Big

The compiler is open source. Read it in the T.O.A.L. repository.

The problem

Programming syntax is a barrier for newcomers. T.O.A.L. is written like plain English so beginners can express logic without learning symbols first, while still covering the basics real programs need: variables, lists, conditionals, loops and reusable functions.

Approach

  • A compiler pipeline in Node.js: an Ohm grammar parses the source, an analyzer checks scopes and types and builds a program graph, and a generator emits JavaScript
  • Plain-English syntax for variables and arithmetic, such as make a with 55; add 1 to x; and 9 plus 10
  • Familiar keywords renamed: function becomes automation, return becomes output, else becomes ifnot, and for and while become loop over and loop while
  • Types renamed to approachable words: word, number, boolean and list
  • A built-in list structure with append and remove, plus conditionals, loops, custom automations and # comments
  • The full syntax is documented side by side with its JavaScript equivalent, so learners can see how each idea maps to traditional code

Example

make list with [1, 2, 3, 4, 5];
loop over element in list {
  add 1 to element;
  print element;
}

automate addNums(num1, num2) {
  output num1 plus num2;
}
A loop and a custom automation in T.O.A.L.

Highlights

  • Plain-English syntax for variables, math, lists, loops and conditionals
  • Custom automations (reusable functions)
  • Syntax reference with JavaScript comparison tables
  • Built by a team of four, with its own website

Ask my site

Ask about T.O.A.L..

Answers come only from the content on this site. If it isn't here, it'll say so and point you to my email.

Answers are generated from this site's content, so double-check anything important.

Psst, this page has a cheat code.