Folio Red
April 7th, 2024

Small Calculator

Date: Unknown, but probably around 2005

Status: Retired

Give me Delphi 7, a terminal control, and an expression parser, and of course I'm going to build a silly little REPL program.

I can't really remember why I though this was worth spending time on, but I was always interested in little languages (still am), and I guess I though having a desk calculator that used one was worth having. I was using a parser library I found on Torry's Delphi Pages (the best site at the time to get free controls for Delphi) for something else, and after getting a control which simulated a terminal, I wrote a very simple REPL loop which used the two.

Example of basic usage.
Example of basic usage.


And credit to the expression parser developer: it was pretty decent. It supported assignments and quite a number of functions. Very capable for powering a desk calculator.

List of functions the parser library supported.
List of functions the parser library supported.


For a while the app was simply that. But, as with most things like this, I got the itch to extend it a little. I started by added a few extra commands. Simple things, like one that would echo something to the screen. All quite innocent, if a little unnecessary. But it soon grew to things like if statements, blocks using curly brackets, and function definitions.

It even extended to small batch scripts, like the one below.  The full set of commands is listed here.

x := 2
y := 3

if {x = y} {echo 5} \
  {echo 232}

return 

These never went anywhere beyond a few tests. The extra commands was not really enough to be useful, and they were all pretty awful. I was already using a parser library so I didn't want to spend any time extending it. As a result, many of these extensions were little more than things that scanned and spliced strings together. It was more of a macro language rather than anything else.

The full set of extensions.
The full set of extensions.

Even with the expression parser the program didn't see a great deal of use. I was working on the replacement at the time which would eventually be much more capable, and as soon as that was ready, this program fell out of use.

Even so, it was still quite a quirky little program to make a bit of an impression.