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.

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

About Jim ...

Jim Lawless' Assembly Language Blog