Brainfuck-IDE / Interpreter current version: IDE : V1.4.1 (13.1.2004) Engine: V1.4.1 (13.1.2004) Author email: helms@uni-kassel.de all rights reserved, intended to publish under GPL-license Gottfried Helms Kassel ================================================================== Brainfuck-IDE ================================================================== Current version v1.4.1 Last changes: minor modifications over ini-file-sections corr 1.4.1 : bug in engine concerning circularity errorchecking on balance of brackets Version V1.1 ----------------------------------------------------- this implements a development environment for brainfuck-interpreter - code-editor as richedit-texteditor - compiler - execution Input as single-char-entry via edit-field Output as single-char-output as string to richedit-lines (some bytes (bytes 0..31) cannot be seen in output!) in monospace-font Endless loops can be aborted by BREAK-button. input/output programs via text-files, extension *.bf preferred new in Version V1.2 ------------------------------------------- language-localization by initialization-file bf.ini (must be stored in application-directory) the existence of the bf.ini-file is required from this version! new in Version V1.3 ------------------------------------------- disassembler-mode (language-localizable) new in version V1.4 ------------------------------------------- see chapter "engine" (customizable datatype,~array) bf.ini-files partly adapted and restructured ================================================================== Brainfuck-Engine ================================================================== brainfuck-engine Vers 1.4.1 2004-01-09 G.Helms Kassel this engine implements brainfuck standard Vers.: ???? coded in Delphi (Vers 6) programming-language This engine is designed to *not* require GUI Author email: helms@uni-kassel.de all rights reserved, intended to publish under GNU-license Gottfried Helms Kassel Version 1.4 : cinfigurable datatype & size; circularity of dataarray Version 1.3 : a disassembler-mode is implemented Version 1.2 : a debug-mode is implemented Version 1.1 : general improvements,configurable input/output channels Verison 1.0 : basic engine, data=byte since Brainfuck Version 1.1 : ----------------------------- code is passed to the engine as a long string with the procedure GetCode(); string can contain any characters; only valid BF-tokens are extracted GetCode analyses and generates an codearray of appropriate length, containing only BF-tokens. The array is allocated based[0], but first code is in code[1] Its index is maintained in integer variable CP The []-parenthesed-blocks of code are maintained by a jump-list, which is created in procedure CmpJmp and must be called after GetCode-procedure. For the computation of jump-adresses an internal stack is temporarily created, which manages corresponding brackets. Execution is called by function EXEC which returns a number for msg, if an error occurs. The data-array is only created at start of execution with length of CMaxDlen (currently $10000 ~ 65565) in an [0]-based array working only on the entries [1]..[dmaxlen-1] BreakRequest An endless execution (for instance erroneous loop) can be aborted. This is controlled by the BreakReq-variable. Since this variable can only meaningfully be set during execution, the execution must allow other windows-events while executes to have set this variable independently on user request. Thus another procedure should be implemented by the main-application, which could simply implement application.processmessages. This is controlled by the procedure-variable DOEVENTS. The default implementation does nothing. Input & output-channels are implemented as procedure putch(byte) function getch:byte; as procedure-variables. For these variables the calling application must provide meaningful procedure-implementations as object-methods (for instance, procedures of the Main-form-object) The procedure/function-variables PUTCH,GETCH should be assigned to that application-specific procedures after creation of the BF-instance. For safety there are defaultprocedures implemented, which are just doing nothing. You need the following minimal process: // initialization bf:=tbf.create; // assign communication-channels between engine & application bf.putch:=myfrm_putchImplementation; bf.getch:=myfrm_GetchImplementation; bf.doevents:=myfrm_DoeventsImplementation ; //only if abort-mechanism is required //pass your code to bf to be compiled bf.Getcode(',++.') ; // interpret BF-code provided by a long-string // the string can contain comments etc. bf.CmpJmp ; // comptes jump-table for block-control by brackets "[]" //execute your code, getting eventually errormessages errcode:=bf.exec; if errcode<>0 then application.messagebox('error:',errmsg[errcode]); //optionally you can free the data-array after execution freedata; // you can perform multiple execs and/or compilings without // re-creating the engine // .... //delete bf bf.destroy; since Brainfuck-Engine Version 1.2 : ----------------------------- Version 1.2 : a debug-mode is implemented For debugging the application can implement a procedure, which for instance, shows the current data-array on the screen before or after each step of code. For this another channel is defined with the procedure variable DEBUG, which must then be assigned to the appropriate applications implementation. If it is not assigned, nothing happens. If it is assigned, then * after GetCode * after CmpJmp * begin of Exec after creating DataArray * performing exec before and after each instruction * end of exec before returning this procedure is called, providing the code- and datapointer and the code-,jmp- and dataarray for the application. Assign this channel after bf.creation, when you assign the other channels as well. since Brainfuck-Engine Version 1.3 : ----------------------------- Version 1.3 : a disassembler-mode is implemented For disassembling of given brainfuck-programs into a readable assembler-like-language. Standard-instructions + INC - DEC > FOC + (means "move focus") < FOC - , GET . PUT [ WHILE [FOC]>0 BEGIN ] END Following optimizations were additionally implemented. repeated Instructions to Instructions with operand +++ INC 3 >> FOC +2 .. PUT *2 Composite Instructions to new single instructions [-] CLR //clears current position [->>>>+<<<<] MOV +4 //moves value to 4 positions right [->>>>++++<<<<] MUL *4 TO +4 //multiplication into new position [-->>>>+++++<<<<] MUL *5 div 2 TO +4 //rational multiplication into new position //For MOV and MUL the following rules are in effect: //* initial position will be cleared //* all 4 variations of all these themes are detected // example given: the four variations of MOV +2 // MOV +2 [->>+<<] // [>>+<<-] // MOV -2 [-<<+>>] // [<<+>>-] since Brainfuck-Engine Version 1.4 : ----------------------------- Version 1.4 : more configuration * size of data-array and size of data-type (byte,word,longword) * datavalue and dataarray circular customizable by bf.ini-file. ================================================================= External definitions. http://esoteric.sange.fi/ENSI/brainfuck-1.3.txt http://esoteric.sange.fi/ENSI/golf-rules.txt