Go to the first, previous, next, last section, table of contents.


5. Syntax of COBOL programs

5.1 Reference Format

Not done yet...

5.2 Preprocessor

Intro... not done yet... what it does, how it fits in.

5.2.1 COPY Verb

5.2.1.1 COPY Verb Examples

COPY a.
COPY a OF b.
COPY "a" of "b".
COPY A replacing
        X by Y
        P of Q of R (1 2 a + 1 b - 2 c) (3: 4*4+1)
        FUNCTION MAXIMUM (A) by ====
        1.0 by 2.0
        ==Gumby people "abc"== by 
          ==Brumby people 'XYZ'==.

5.2.1.2 COPY Verb Syntax

As per the COBOL 85 standard with extensions.

COPY text-name-1 | non-numeric-literal-1 
     [{OF|IN} library-name-1|non-numeric-literal-2]
[       
 REPLACING 
 {
        { ==pseudo-text-1== | identifier-1 | literal-1 | word-1 } BY
        { ==pseudo-text-2== | identifier-2 | literal-2 | word-2 }
 } ...
] .

5.2.1.3 COPY Verb Restrictions

Up to 10 levels of nested copy is allowed. This limit can be changed via a compile time option. All COPY verbs can have REPLACING clauses within them.

A COPY verb can appear anywhere in the source program or in a library, except in a comment, literal or comment-entry. It can even appear within a REPLACE verb for example.

5.2.1.4 COPY Verb Processing

If REPLACING is not specified, the file is copied into the source program without change. The copied file starts on a new line and after it ends, the next text from the source file that contained the COPY verb will be on a new line.

If REPLACING is specified, the file is copied into the source program with replacements specified (see below).

5.2.2 REPLACE Verb

5.2.2.1 REPLACE Verb Examples

 REPLACE ==forward-verb-buffer-size== by 1000.

  01 FVB-ARRAY.
    02  FVB-ENTRY PIC 9(3) OCCURS forward-verb-buffer-size. 

  PERFORM VARYING IX FROM 1 BY 1 UNTIL IX GT forward-verb-buffer-size
    blah blah blah
  END-PERFORM.

Gives

  01 FVB-ARRAY.
    02  FVB-ENTRY PIC 9(3) OCCURS 1000.

  PERFORM VARYING IX FROM 1 BY 1 UNTIL IX GT 1000
    blah blah blah
  END-PERFORM.

5.2.2.2 REPLACE Verb Syntax

REPLACE {== pseudo-text-1 == by == pseudo-text-2 == ...} .

OR

REPLACE OFF.

This verb replaces text within the program with other text. It is a good way to define array sizes etc and have all the relevant variables set up.

After all the COPY verbs are processed, producing a single conceptual output file, the REPLACE verbs are processed. Only one or no replace is active at a given point in the code.

REPLACE OFF turns off replacing. Only the last REPLACE verb is in effect at any time. So each REPLACE turns off the previous REPLACE.

The REPLACE verb should start in area b.

5.2.2.3 REPLACE Verb Processing

5.3 Definitions of syntactic elements and terms.

  1. array_expression
    identifier
    OR
    integer
    OR
    identifier + integer
    OR
    identifier - integer
    
  2. expression
    identifier
    OR
    numeric_literal
    OR
    expression + expression
    OR
    expression - expression
    OR
    expression / expression
    OR
    expression * expression
    OR
    expression ** expression
    OR
    ( expression )
    
  3. identifier
    word {[of/in word] ...} [(array_expression ...)] [([expression]:expression)]
    #end example
    
    That is...
    1. a name...
    2. possibly qualified...
    3. possibly with array references (any expression is allowed per array dimension)...
    4. possibly with reference modification
    May also be a function reference...
    FUNCTION function-name1 [([expression or identifier ...])]
    
  4. integer a sequence of digits, no sign eg 44, 101, 0. Not +1, -1.
  5. literal A numeric literal of a non-numeric literal.
  6. non-numeric-literal
    1. basically a character string eg "abc123"
    2. can be enclosed in single quotes eg '123abc'
    3. can include quotes as follows
      "abc""123" -> abc"123
      'abc''123' -> abc'123
      'abc"123' -> abc"123
      "abc'123" -> abc'123
      
      In the main compiler, hex strings are allowed (x"hhhh...") but not in the preprocessor. Non-numeric literals are case sensitive.
  7. numeric literal
    [+-][99][.][99]
    
    1. Must have at least one digit
    2. Sign is optional and must be leftmost if present. One decimal point max.
    3. Decimal point can be a comma to accommodate 'decimal point is comma' possibility.
  8. text word
    1. a literal
    2. OR a separator (", " ". " "==" or one or more spaces)
    3. or any other sequence of contiguous characters except COPY.
  9. token This refers to any word or literal or other element of a COBOL program, such as "=".
  10. word A COBOL name. Rules are
    1. consists of 0-9a-zA-Z plus "-".
    2. "-" must not be first or last character.
    3. must not all be 0-9.
    4. length <= 30 characters (extension - can be > 30 characters, a warning will be given).
    5. May also be an arithmetic operator: + - < > <= >= ** *


Go to the first, previous, next, last section, table of contents.