🍱 bento — A New English-based Automation Language for Non-technical People

Elliot Chance
Aug 7 · 5 min read
Photo by Franck V. on Unsplash
start:
display "Hi, I'm bento."

What is bento?

https://github.com/elliotchance/bento

bento is a forth-generation programming language that is English-based. It is designed to separate orchestration from implementation as to provide a generic, self-documenting DSL that can be managed by non-technical individuals.

Wow, what a mouthful… That’s a bunch of fancy talk that means that the developers/engineers can setup the complex tasks and make them easily implementable by non-technical people through (almost) plain English.

The project is still very young, but it has a primary goal for each half of its intended audience:

For the developer/engineer: Programs can be written in any language (called a backend) and easily exposed through a set of specific DSLs called sentences.

For the user: An English-based language that avoids most nuances and complex grammar that non-technical people would find difficult to understand. The language only contains a handful of special words required for control flow. Whitespace and capitalization do not matter.

What Does bento Look Like?

It is possible to write programs that are entirely within the bento language (not using any backends, explained shortly). Here is an example in the file hello.bento:

Start:
Say hello to "Jane"
Say hello to "David"

Say hello to persons-name (persons-name is text):
If it is the afternoon,
display "Good afternoon, " persons-name "!",
otherwise display "Good morning, " persons-name "!"

It is the afternoon?
Declare am-or-pm is text
Run system command "printf `date +'%p'`" output into am-or-pm
If am-or-pm = "PM", yes

Let’s run it:

$ bento hello.bento
Good afternoon, Jane!
Good afternoon, David!

Some very basic language rules to be aware of:

Even through bento programs can be written entirely in the bento language, this is not its intended purpose. Bento is designed to orchestrate one or more backends that do the actual work.

What Will We Be Building?

To demonstrate, here is the bento program we will be implementing:

start:
declare scores is example-scores-php
declare avg is number

add 53.5 to scores
add 17 to scores

average of scores into avg

display avg
display scores

Hopefully the program steps itself are pretty self-explanitory. By the time we finish, we will be able to run this and see the result:

35.25
The total is 70.5.

Before we can implement our backend, we need to understand how the lifecycle of a backend works:

  1. declare is used to declare a variable, but it also starts the backend. The type is the name of the backend (example-scores-php in this case). For this example I will use PHP because it’s pretty common. However, the name of the backend is totally unrelated to how the backend works.
  2. A backend is a directory by the same name. Bento will search for the backend in all directories defined in the $BENTO_BACKEND environment variable, which works similar to $PATH. It may contain zero or more paths split by a :. If $BENTO_BACKEND is not defined or is empty then it will receive a default value of . — the current directory.
  3. Bento will start and communicate with the backend through a simple text based socket protocol. Which we will build in PHP next.

Creating the Backend

We start by creating a directory called example-scores-php . Put it in the same directory as where we will run the script to make things easy. In this directory there will be three two files:

  1. bento.json describes how the backend should be started. More on this later.
  2. scores.php (The backend can be in any language because the backend will responsible for it’s own server. For this example I will use PHP because it’s pretty common):
<?php// This file is an example of a backend written in PHP.$handlers = [
'add ? to ?' => function($args) use (&$total, &$count) {
$total += $args[0];
++$count;
},
'average of ? into ?' => function($args) use (&$total, &$count) {
return ["set" => ['$1' => (string)($total / $count)]];
},
'display ?' => function() use (&$total) {
return ["text" => "The total is $total."];
}
];
// The code following should not need to be changed.$socket = socket_create(AF_INET, SOCK_STREAM, 0);
$result = socket_bind($socket, "127.0.0.1", $_ENV['BENTO_PORT']);
$result = socket_listen($socket, 3);
$spawn = socket_accept($socket);
while ($message = json_decode(socket_read($spawn, 65536, PHP_NORMAL_READ))) {
if ($message->special === "sentences") {
$result = ['sentences' => array_keys($handlers)];
} else {
$handler = $handlers[$message->sentence];
$result = $handler($message->args);
}
if (!$result) {
$result = new stdClass();
}
$output = json_encode($result) . "\n";
socket_write($spawn, $output, strlen($output));
}
socket_close($spawn);
socket_close($socket);

bento.json is quite simple:

{
"run": "php scores.php"
}

This example is also part of the main bento repository: https://github.com/elliotchance/bento/tree/master/backend/example-scores-php


That’s it! We simply run it:

bento scores.bento

How Is the Language Implemented?

Bento is an interpreted language, but it has a lexer, grammar, compiler and virtual machine. You can find the full language specification in the README.

What’s Planned For The Future?

I want to keep the language itself very simple and allow extension through people creating their own packages. That being said, there are some things that I believe must be implemented to create a productive environment for everyone:

  1. IDE in the browser. Bento can run as a server, exposing an IDE through the browser to edit and run programs. Nice features like code coloring, autocomplete, drag and drop script editor, debugger, etc.
  2. Richer built-in types including arrays, structures and time. These will make writing programs that interact with structured data (like a database or CSV file) much easier.
  3. GUI development. There are many great frameworks out their for building native and web GUI apps. I’m not sure what this will look like yet, but being able to create interactive forms, lists, graphs, etc. would make it easier to present simple interfaces that connect and communicate with complex backend systems without having to build and maintain that software through traditional means.

I’d Love To Hear From You

As I said, it’s still early days. While all the difficult technical parts have been completed there is still a lot of polish to be added that can only really be done with feedback from users.

If this is something that interests you, I’d love to get any kind of feedback. You can find my email on my Medium profile.

The Startup

Medium's largest active publication, followed by +539K people. Follow to join our community.

Elliot Chance

Written by

I’m a data nerd and TDD enthusiast from Sydney. I love exploring new technologies and working on modern ways to solve age old problems 🤓 elliotchance@gmail.com

The Startup

Medium's largest active publication, followed by +539K people. Follow to join our community.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade