Attachmate EXTRA! is terminal emulation software to connect to mainframes. Part of this software is a Basic interpreter that allows you to write automation macros that do screenscraping on terminal screens. The scripting language used is called Extra Basic. Scripts have the extension .ebm, which stands for Extra Basic Macro.
This scripting language is a lot like Visual Basic, or QBasic and most code you can simply Copy & Paste. But there are differences.
At work, when extending an old macro (made by a now retired colleague) with printing capabilities I ran into some limitations of Extra Basic.
In QBasic there used to be a command LPRINT to send text to a line printer. Neither Visual Basic or Extra Basic have this command. To print from Visual Basic you use the Printer object, but to print from Extra Basic you need another approach.
It’s pretty easy to define an interpreter in Prolog. How this can be done is shown in this paper.
You can download my interpreter here. It takes a slightly different approach than described in the paper to allow for tail recursion. Without this optimization, running any brainfuck program more complex than ‘hello world’, would result in a Prolog ‘Out of Stack’ error. For some tips on writing efficient Prolog programs check out this document. The Prolog environment I used is SWI-Prolog.
I’ve included some brainfuck programs I found at ‘The brainfuck archive’.
To start a brainfuck program from Prolog do the following:
It’s not the fastest interpreter around, but it’s a nice example of how to build one in Prolog.