Documentation for Code-Compiler for Cobol version 0.01 The version 0.01 Cobol compiler was designed to take a cobol source program and translate it into source code which would compile using the FreeBasic compiler. It is designed to accept a limited subset of the Cobol language for the express purpose of beginning the process of self-hosting a Cobol compiler, i.e. to allow the Cobol compiler to itself be written in Cobol. The program is, for all intents and purposes a "one-shot" compiler; it's designed to allow the compiler to generate itself as a program in Basic. Once the Cobol compiler can translate itself, further work with this program will cease as at that point the work will continue with the Cobol Compiler source. At that point the compiler version will be 0.10. As this program is just being done to allow the compiler to be developed, it is limited and has certain requirements for the program submitted to it. The source file to be read is named "SOURCE.COB". The output file is named "DEST.BAS". These are hard-coded. The program should be correct. This is not a full compiler and doesn't do error checking other than minor tests. Garbage in will equal garbage out. ALL keywords MUST BE IN UPPER CASE. Only 01 levels are permitted in FD Only 01 and 05 levels are permitted in Working Storage. 05 Levels must be subordinate to an 01. Only PIC X and PIC 9 are available. Define PIC 9 only as 01 level and do not create a subordinate 05 level. Names used in 01 level and 05 levels must be unique. Define all quoted literals as an 01 value in working storage, and use the defined name of that quoted literal in place of a quoted string. Don't use quoted literals anywhere else. Spaces may be important in some areas outside quoted strings. Use care if inserting more than one space between items. Don't put a space immediately before a period. All paragraphs must begin with a 2 as the paragraph name. Variables of type Pic 9 will all be type COMP, e.g. integer; size is ignored. There is no floating point. READ and WRITE should be directed to the name on the select statement (select-name). You can use MOVE to transfer data from the identifier in the FD clause to any areas to work on the information. Only picture X is supported for READ or WRITE. Only one statement per line is processed. Where a statement is an imperative statement for an IF or READ statement, only one statement following the IF or READ is allowed. Margin a and b are ignored. Sequence number is saved for error reporting (if any) and may be blank. Column 7 * is a comment and is ignored. Division and section headers aren't needed but may be included. IDENTIFICATION DIVISION. Completely optional; Only permitted statement is PROGRAM-ID. identifier. identifier is saved but not used. ENVIRONMENT DIVISION. These three may be included; they are ignored. ENVIRONMENT DIVISION INPUT-OUTPUT SECTION. FILE-CONTROL. To use a file it must be selected SELECT select-name ASSIGN TO "quoted file name". this select name must be referenced by an FD. DATA DIVISION. The following may be included; they are ignored. DATA DIVISION. FILE SECTION. WORKING-STORAGE SECTION. A file chosen with select must be defined by FD FD select-name. This is immediately followed by an 01 level identifier. 01 file-buffer PIC X(80). which defines the size of the buffer for the file. Reads will automatically populate this area; writes will automatically write from this area. This area cannot be subdefined with 05 level. Entries in Working Storage are as follows 01 identifier PIC X(amount) [VALUE 'text']. or 01 identifier-1. 05 identifier-2 PIC X(amount) [VALUE 'text']. 05 identifier-3 PIC X(amount) [VALUE 'text']. PROCEDURE DIVISION. The following Procedure Division statements are allowed 2paragraph-name. -- Defines start of a paragraph. Must begin with '2'. CLOSE select-name. -- Close open file DISPLAY identifier. -- Print message on console IF MOVE OPEN INPUT select-name. -- Open a file for reading OPEN OUTPUT select-name. -- create a file for writing PERFORM paragraph-name PERFORM paragraph-name UNTIL condition. READ -- read from an open file STOP RUN. -- end program WRITE select-name. -- write to an output file If statement is of form IF condition statement. or IF [NOT] AT END select-name statement. Condition is identifier = | <> | < | > identifier MOVE identifier-1 [identifier-2 [identifier-3]] TO identifier-target. If identifier-2 is specified, it is concatenated to the end of identifier-1. if Identifier-3 is specified, it is concatenated to the end of identifier-2. READ statement is of form READ select-name. or READ select-name AT END statement.