How to create a web scripting language



 About 10 years ago I created a version of the Forth language that could be mixed with html like c# or javascript. Apache and IIS may be configured to send a web page with a custom extension to an executable that pre-process the page. The extension I wrote looks for the tags <?4th ….. ?> in the web page and sends the text between to the 4th language’s parser. Output from the Forth executable is mixed with the html on the resulting web page and sent by the web server to the user’s browser. The 4th interpreter injects the html it produces replacing the <?4th> zzzz z zz ?> tag area. 

For example in my 4th the image below shows a printgreen function written in 4th in page script and also shows the result seen in the browser.

View source in the browser shows the html that was created and sent from IIS.

What is being done by the 4th script engine is 

·        parse the webpage source looking for <?4th and ?> tags

·        extract the text between the tags and send it to the Forth language input buffer

·        tell the 4th language to parse and interpret the commands now in its input buffer

·         output the result

The source code for my 4th scripting language is downloadable at  ( The current source is a Visual Studio 2013 project it should compile on older compilers. The output file after the source is compiled is named forthwsc.exe

To enable 4th in my web server IIS, I follow the steps shown in the images below (I am using version 8 here but Apache and older versions of IIS can do the same thing on windows systems.)

1.)     Add a mime type for pages using 4th.  I used .4hf

   .4hf a mine type for the file extension of the pages using 4th script

2.)    Give forthwsc.exe permission to run from IIS.

 IIS is told that forthwsc.exe is allowed to run.

3.)     Create a mapping between *.4hf and FORTH in IIS

Put your forth script files in a directory under wwwroot so they will be found by a url like ‘http://localhost/forthscript/showgreen.4hf’

I include a script designed to test my version of the 4th language named test4th.4hf in the file with the source code.