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:

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

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:

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

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;
}

Enjoy!

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 https://www.raymondcamden.com

Comments