------------------------------------------------------------------- BACON (BAsic CONverter) manual ------------------------------------------------------------------- BACON is a simple BASIC implementation which translates into C-code. The C-code can be compiled with GCC (GNU C Compiler) or CC (Tru64 Compaq C Compiler). BACON does not need linenumbers. One statement per line is accepted. If there are more statements on the same line then these are ignored. BACON consists of statements, functions and expressions. Each line should begin with a statement. Functions always return a value to a variable or statement (like PRINT) but also can be used standalone. Expressions are not converted but are passed unchanged to the C compiler. Variables will be declared implicitely from the first moment a variable is used. If a variablename ends with the '$' symbol, a string variable is assumed. Otherwise it is regarded as numeric. By default, BACON assumes long type with NUMBER variables. With the 'DECLARE' statement it is possible to define a variable to any C-type explicitely. The three maintypes in BACON are defined as STRING, NUMBER and FLOATING. Subroutines may be defined using SUB/ENDSUB. These SUB routines do not return a value. With FUNCTON/ENDFUNCTION routines can be defined which do return a value. The returnvalue must be explicitely stated with the statement RETURN. Variables which are used and declared within a SUB or FUNCTION have a global scope, meaning that they are seen by the mainprogram and other routines. With the LOCAL statement variables explicitely can be declared local to the FUNCTION or SUB. String variables always are passed by reference to a SUB or a FUNCTION. ========================= STATEMENTS - PROGRAM FLOW ========================= WHILE DO [BREAK] WEND - Loop while is true REPEAT [BREAK] UNTIL - Loop until is true FOR var = x TO y [STEP z] [BREAK] NEXT [var] - Loop from x to y with optional step z. If x > y then STEP must be negative. IF THEN [ELIF] [ELSE] [body] ENDIF | END IF - Execute if is true. SUB [(STRING s, NUMBER i, FLOATING f)] ENDSUB | END SUB - Define subprocedure. Used variables are local to the subprocedure. Instead of the Bacon types STRING, NUMBER and FLOATING for the incoming arguments, also regular C-types also can be used. FUNCTION ()|(STRING s, NUMBER i, FLOATING f) RETURN ENDFUNCTION | END FUNCTION - Define function. Used variables are local to the function. Value should be returned explicitly with the RETURN statement. Instead of the Bacon types STRING, NUMBER and FLOATING for the incoming arguments, also regular C-types also can be used. USEC ENDUSEC | END USEC - Define a body with C code. This code is passed unmodified to the C compiler. ================ STATEMENTS - I/O ================ PRINT [value] | [text] | [variable] | [expr] [FORMAT ] | [,] | [;] - Prints a numeric value or variable or result from expression. A semicolon at the end prevents printing a newline. Multiple arguments maybe used when separated with a comma. INPUT - Gets input from the user. OPEN FOR READING|WRITING|APPENDING|READWRITE|DIRECTORY|NETWORK|SERVER AS - Opens a file assigning a handle to it. When used with DIRECTORY a directory is opened as a stream. When used wth NETWORK a network address is opened as a stream. When used with SERVER the program starts as a server to accept incoming TCP connections. CLOSE FILE|DIRECTORY|NETWORK - Close file, directory or network identified by handle. READLN FROM - Read a line of data from a file identified by handle into a variable WRITELN TO - Write a line of data to a file identified by handle GETBYTE FROM [SIZE x] - Retrieve binary data into a memory area from a file identified by handle with optional size of x bytes (default size = 1) PUTBYTE TO [SIZE x] - Store binary data from a memory area to a file identified by handle with optional size of x bytes (default size = 1) RECEIVE FROM - Read data from a network location identified by handle into a variable. Subsequent reads return more data until the buffer is empty. SEND TO - Send data to a network location identified by handle WAIT(networkhandle, milliseconds) - Suspend program for a maximum of until data becomes available on . GETFILE FROM - Read a file from an opened directory. Subsequent reads return all files. ENDFILE(filehandle) - Check if EOF on file opened with handle is reached. REWIND - Go back to the beginning of the opened file. SEEK OFFSET [WHENCE START|CURRENT|END] - Put filepointer to new position at offset, optionally starting from . SEARCH(handle, string) - Search for a in file opened with . Move filepointer to the position of the string. TELL(x) - Return current position in file with handle x. COPY TO - Copy a file to a new file RENAME TO - Rename a file. If different paths are included the file is moved from one path to the other. DELETE - Delete a file or directory FILELEN(filename) - Return the size of . MAKEDIR - Create empty directory. CHANGEDIR - Change working directory. COLOR TO | COLOR - Set coloring for output of characters in terminal screen (ANSI compliant terminals) GOTOXY x, y - Put cursor to position x,y where 0,0 is upper left of terminal screen (ANSI compliant terminals). Only accepts numbers. CLEAR - Clears the terminal screen (ANSI compliant terminals) =================== STATEMENTS - MEMORY =================== MEMORY(x) - Claim memory of x byte size, return starting point RESIZE x, y - Resize memory area pointed to by x with y bytes POKE x, y - Store 1-byte value y at memory addres x PEEK(x) - Return 1-byte value stored at memory address x ADDRESS(x) - Return memory address of variable x FREE x - Release claimed memory ================== STATEMENTS - OTHER ================== LET = | - Assign a value or result from an expression to a variable. LET may be omitted. CONST = | - Assign a value or result from an expression to a constant variable. LOCAL [,var2,var3,...] TYPE - Define a local variable with C type GLOBAL [,var2,var3,...] TYPE - Define a global variable with C type RECORD LOCAL TYPE LOCAL TYPE .... END RECORD - Define a record with members. The members should be defined with the LOCAL statement and can be accessed with the 'var.member' notation. DEF FN