Jim Lawless' Blog

BPL: Batch Programming Language Interpreter

Originally published on: Tue, 12 May 2009 01:39:26 +0000

In the latter part of the year 2000, I decided to write a commercial programming language interpreter called BPL - Batch Programming Language.

I had envisioned a language that would employ a simple syntax similar to the syntax used by MS-DOS/Windows batch file scripts.

This language would employ no expressions nor true user-defined functions; each line of code would simply contain a command and a list of arguments that could be coupled with that command. Often, a variable name ( without the $ prefix ) was required as the first parameter so that a value computed by the given command could directly be stored in the specified variable.

Consider this sample BPL program


echo "Math demo"

set a 2
set b 5

add c $a $b
echo $a " plus " $b " equals " $c

sub c $a $b
echo $a " minus " $b " equals " $c

mul c $a $b
echo $a " times " $b " equals " $c

div c $a $b
echo $a " divided by " $b " equals " $c

mod c $a $b
echo "The remainder of " $a " divided by " $b " is " $c

and c $a $b
echo $a " and " $b " is " $c

or c $a $b
echo $a " or " $b " is " $c

xor c $a $b
echo $a " exclusive-or " $b " is " $c


The output of the above program is:

Math demo

2 plus 5 equals 7
2 minus 5 equals -3
2 times 5 equals 10
2 divided by 5 equals 0
The remainder of 2 divided by 5 is 2
2 and 5 is 0
2 or 5 is 7
2 exclusive-or 5 is 7

Press ENTER to continue...

Note that like batch files and TCL, ( Tool Command Language ) the variable names do not have a $ prefix if they are a target of an assignment. The only time a variable name has a $ prefix is if the variable represents a value and is to be expanded to said value.

While BPL did entertain a modest success, the product was not popular enough for me to continue work on the BPL compiler that I had begun to write. If you study the BPL source, you'll see that I made a number of design flaws that would have made supporting the initial syntax with a compiler clumsy at best.

The EXTGOSUB and EXTRETURN verbs allowed one BPL script to invoke a subroutine in another. I should have added some sort of IMPORT or MODULE or REQUIRE verb so that the primary script would have to define all modules that it intends to leverage with EXTGOSUB. That alone would have ensured that a BPL compiler could have recursively derived the names of all subordinate files to ensure that all were captured in the compilation process.

Like the venerable COMMAND.COM, BPL keeps the script files open while executing. I had begun to implement a caching mechanism that would load each file into a block of memory and would keep it there, but in the interpreter flavor of BPL this would have prevented someone from building a script dynamically and then invoking it with an EXTGOSUB.

Other things I would change:

  1. I would not use macros for manipulation of the various stack data-structures employed by BPL. I would use functions that would check for underflow/overflow conditions.
  2. I would pre-parse each script instead of brute-force constantly re-parsing each line.
  3. I would implement a more efficient variable lookup. At first, I had assumed that a hash table implementation might work better than the sequential lookup currently used, but today I would opt to use a most-recently-used (MRU) linked-list.

I had implemented a WHILE/WEND combination so that I could avoid using the GOTO ( why did I put GOTO in the language? ), but I've since lost the source to that implementation.

As I released BPL, I was aware of commercial utilities like WinBatch, but new contenders were making names for themselves. AutoIt and AutoHotKey arrived on the scene, sporting more popular syntaxes and very impressive community support.

I retired BPL a few years ago and have recently decided to release the interpreter source and documentation as open source.

The source code, EXE, sample scripts, and HTML documentation for BPL can be found here.


Unless otherwise noted, all code and text entries are Copyright 2009 by James K. Lawless.

Views expressed in this blog are those of the author and do not necessary reflect those of the author's employer. Views expressed in the comments are those of the responding individual.

stumbleupon Save to StumbleUpon
digg Digg it
reddit Save to Reddit
facebook Share on Facebook
twitter Share on Twitter
aolfav More bookmarks

Previous post: Throwaway Software: HangUp
Next post:A DSL in JavaScript

About Jim ...

Follow me on Twitter


My GitHub Repository


Recent Posts

Compiling C from the Command Line with Pelles C

A Forthcoming Marvel Movie Villain

Uninstalling Problematic Windows Software

Don't be Hatin'

A JavaScript REPL for Android Devices

MailSend is Free

My Blog Engine

The October 10th Bug

Random Posts

WSH2EXE - The Final Chapter

Charging by the Byte

Blog Posts by Category

Locking a Windows Session

We've Moved!

An Interview with Tom Zimmer: Forth System Developer

A Command-Line CD Tray Opener

Internet Protocols and Rhino JavaScript

Screen Captures with Java and Clojure

Expanding Shortened URL's

Full List of Posts


Recent Posts from my Other Blog / GitHub

Growing Up with Radio Shack

A BBCode Tag to Display Temperatures in Celsius and Fahrenheit

Fare Thee Well, Dr. Dobb's Journal

Using Standard C Libraries with Yosemite JavaScript

JavaScript Libraries in Yosemite

Command Line JavaScript in Yosemite

Text to Speech, Yosemite, and JavaScript

A Simple (but useful) TCP Client Written in Go

Yet Another Seven Languages in Seven Weeks

Happy 50th Birthday, BASIC

Extending Commodore 64 BASIC

Hide the HTTP-Referer using HTML and JS

RSS Feed Processing in Python

A Chromecast Slideshow using Python

A Simple Perl REPL

Linux Mint on a Toshiba Netbook

Find and View All Images on a HD with Perl

Pretty-Printing an s-expression in Go

My Personal Text to HTML Utility

1985 Computing : Atari and Commodore

My Mac has Mono

Yet Another Config File Reader for Go (Golang)

Filling a Slice Using Command-line Flags in Go (Golang)

An RPN Interpreter in Go (Golang)

Simulating Try-Catch in Go (Golang)

Sending GMail with Go (Golang)

Variant Types in Golang

My First C64 Interrupt Program

The Triangles Puzzle

Happy 25th, Perl !

My Favorite BASIC One-Liner

Playing with OS/X Text to Speech

The Villain at the end of Marvel's Avengers Move is...

Chicken! Fight like a Robot!

Processing GMail items with Ruby

The Squares Puzzle

Happy 30th Birthday, Commodore 64

Scripting Safari

MailWrench CSharp Command Line Mailer for Windows is now Free Software

Welcome Back, M.U.L.E. !

Rainy Day Fun with the HTML DOM

Building a World War II Foxhole Radio

Prototerp Unleashing a JavaScript REPL via the Mobile Browser

Steal This Bookmarklet

Happy Birthday, Miles