Don't Try This At Home: CFBASIC

So, a few years ago I was bored. Really bored. I decided to write a BASIC interperter in ColdFusion. It would allow for stuff like this:

   20 x = 10
   30 if X > 5 THEN goto 60
   40 println <FONT COLOR=BLUE>"x is less than 5"</FONT>
   50 goto 100
   60 println <FONT COLOR=BLUE>"x is more than 5"</FONT>
   110 if x > 5 then x = 2
   115 print <FONT COLOR=BLUE>"x is "</FONT>
   120 println x
   130 if x == 3 then println <FONT COLOR=BLUE>"Yes x is<FONT COLOR=BLUE> 1</FONT><FONT COLOR=NAVY><P></FONT>"</FONT>
   150 if x > -1 then println <FONT COLOR=BLUE>"its 0 or higher"</FONT>
   160 x = -2
   170 if x < 0 then println <FONT COLOR=BLUE>"it is negative"</FONT>

Why did I do this? As I said - I was bored. This is a completely dumb thing to code. That being said, it was fun. :) I have no formal training in writing computer languages, so this is far from perfect, but for those who want to take a look, you can download the code here. Please forgive the upper-case code. I was delusional a few years ago and thought that made for good code writing. The only slightly cool thing about this code is - the core of BASIC was done so that you could add a new feature by writing a UDF. So for example, here is how “print” was done:

<FONT COLOR=GRAY> // currently we only support printing a string or a var</FONT> function cfb_print(arg) {
<FONT COLOR=GRAY>   // strings must be <FONT COLOR=BLUE>" "</FONT></FONT>    if(left(arg,<FONT COLOR=BLUE>1</FONT>) IS <FONT COLOR=BLUE>""</FONT><FONT COLOR=BLUE>""</FONT> AND right(arg,<FONT COLOR=BLUE>1</FONT>) IS <FONT COLOR=BLUE>""</FONT><FONT COLOR=BLUE>""</FONT> and len(arg) gt<FONT COLOR=BLUE> 2</FONT>) WriteOutput(Mid(arg,<FONT COLOR=BLUE>2</FONT>,Len(Arg)-2));
<FONT COLOR=GRAY>   //ok, try to find it in the temp scope</FONT>    if(structKeyExists(CODETEMP,arg)) WriteOutput(CODETEMP[arg]);

The idea was - any UDF with “cfb_” in front was considered a BASIC function. Here is another example, my favorite:

//remarks do nothing
function cfb_rem(arg) {
   return false;


Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA