Webrainfck 0.01 ---------------- This is an implementation of brainf*ck with 3 more instructions, a string macro, and a web syntactic feature. Designed to be run in a similar fashion to CGI processors. Installation ------------ Basically add this CGI program as a handler for .wbf files on your favorite web server. In Apache: Put this in your httpd.conf ScriptAlias /Webrainfckcgi/ "" AddType application/x-Webrainfck .wbf Action application/x-Webrainfck "/Webrainfckcgi/Webrainfck.exe" Instruction Set --------------- > Standard brainf*ck, move ptr right. < Standard brainf*ck, move ptr left. + Standard brainf*ck, increment ptr value. - Standard brainf*ck, decrement ptr value. . Standard brainf*ck, output ptr value. , Standard brainf*ck***, input ptr value. [ Standard brainf*ck, start loop (while ptr value isnt zero). ] Standard brainf*ck, end loop, goes back to [ for re-eval. ` Webrainfck extension, talk to the mongoose. ' Webrainfck extension, talk to the web. @ Webrainfck extension, perform mongoose action, then talk to the web. (*** Unlike console brainf*cks, value input ',' actually only gets its input from the mongoose (see below)) String Slash Macro ------------------ Slashes are used as macros to create the instructions for strings of text (in reverse). Example: [-]> /Hello World!/ <[.<] This will print Hello World! on the screen. While this probably looks like cheating in the usual brainf*ck spirit, this simply makes it easier to create tedious strings of text, as entering legible text in brainf*ck is usually the most tedious yet most trivial thing to do (compared to other things like arithmetic). Nothing prevents you from going about doing this by hand like before. The macro used to create this string is simple: the string starts with [-] and each character is of the form: >[-]A[<++++++++>-] where A is the number in '+'s for ascii(chr)/8 B is the number in '+'s for ascii(chr)%8 Hello World! ^ [-] >[-]++++[<++++++++>-]<+> Hello World! ^ [-] >[-]++++[<++++++++>-]<+> >[-]++++++++++++[<++++++++>-]<++++> Hello World! ^ [-] >[-]++++[<++++++++>-]<+> >[-]++++++++++++[<++++++++>-]<++++> >[-]+++++++++++++[<++++++++>-]<++++> Hello World! ^ [-] >[-]++++[<++++++++>-]<+> >[-]++++++++++++[<++++++++>-]<++++> >[-]+++++++++++++[<++++++++>-]<++++> >[-]+++++++++++++++[<++++++++>-]<+++++> . . . Hello World! ^ [-] >[-]++++[<++++++++>-]<+> >[-]++++++++++++[<++++++++>-]<++++> >[-]+++++++++++++[<++++++++>-]<++++> >[-]+++++++++++++++[<++++++++>-]<+++++> >[-]+++++++++++++[<++++++++>-]<+++++++> >[-]++++++++++[<++++++++>-]<+++++++> >[-]++++[<++++++++>-]<> >[-]+++++++++++++[<++++++++>-]<+++++++> >[-]+++++++++++++[<++++++++>-]<++++> >[-]+++++++++++++[<++++++++>-]<++++> >[-]++++++++++++[<++++++++>-]<+++++> >[-]+++++++++[<++++++++>-]<> Note when handling that the string is always generated in reverse. Syntactic Feature ----------------- <% and %> starts and ends Webrainfck code in a way similar to other "web enabled" languages. It allows embedding code into HTML and embedding HTML into code. Example: blah <%+++++[%>Hello World
<%-]%> This prints out Hello World 5 times in a minimal document. The Mongoose ------------ The mongoose provides certain services to aid with the program's journey towards utility. These services are accessed by outputting a string of values as if outputing to the screen, however by first invoking ` to speak to the mongoose. Upon invoking @ the mongoose will reply from standard input (from ','). The mongoose provides an interface to get standard CGI variables, get decoded form input, change the HTTP headers and opeb SQLite 2.x databases. All mongoose commands are of this format: AAA:BBBBBBB.. where AAA is a three character code for the command to do, and BBBBBBB.. being whatever useful for that command. DBO: Opens a SQLite database DBQ: Executes a SQL query on the open database. As a good practice, don't plug in directly your values into the query, replace the value with a question mark and plug it afterwards with DBP:. DBP: Plugs a value into the next empty "?" in the last DBQ: query. DBR: Retrieves the next row in a currently open result set. returns 1 if there is another row, otherwise returns 0. DBV: Retrieves a value from the current row at the specified column number. DBC: Closes the SQLite database DBN: Repeats the last DBR's reply if there is a next row, returns 1 if so. FRM: Gets the input value for some form key. ENV: Gets the CGI environment value for something HTR: Sets the HTTP Response at the very beginning (like 200, 500, 302, etc.) HTH: Adds an HTTP header. Portability Issues ------------------ brainf*ck programs that don't use input very much will be pretty straightforward to port to WBF. When doing so, get rid of these: ` Reserved for mongoose ' Reserved for mongoose @ Reserved for mongoose / Reserved for macros When there is input used in your program, you should see how different the screen input and the mongoose input will differ, as the web and console are pretty different anyway. It's likely you can push in a couple of mongoose calls between input code blocks to emulate entering stuff from the screen. Apart from the above reserved characters, normal brainf*ck code should be backwards compatible. Also the following behaviour is to be noted: * ','Does not modify value when there is no input. * Cells are standard 8 bit. * The standard 30,000 Cells have been kept. * Any encoding related stuff of the data is undefined. End of line may either have 10 or 13 depending on what the client returns. * All non-instructions are ignored like in standard brainf*ck.