[Skip Navigation] [CSUSB] / [CNS] / [CSE] / [R J Botting] / [Samples] / cobol.syntax
[Index] [Contents] [Source Text] [About] [Notation] [Copyright] [Comment/Contact] [Search ]
Fri Apr 15 09:43:05 PDT 2011

Contents


    Syntax of COBOL Circa 1988

      UML model

      [ COBOL.png?root=atlantic-zoos ]

      ASCII

      [ comp.text.ASCII.html ]

      Lexemes

      COBOL has hundreds of reserved words they are not listed separately her, yet.

      XBNF for COBOL

    1. Identification_Division::= "IDENTIFICATION DIVISION." "PROGRAM-ID." program_name"." (("AUTHOR." | "AUTHOR."comment|) ("INSTALLATION."|"INSTALLATION."comment|) ("DATE-WRITTEN."|"DATE-WRITTEN."comment|) ("DATE-COMPILED."|"DATE-COMPILED."comment|) ("SECURITY."|"SECURITY."comment|)),
    2. comment::= (#character )~definition".",

    3. Environment_Division::= "ENVIRONMENT DIVISION." configuration input_output,
    4. configuration::= "CONFIGURATION SECTION." ("SOURCE-COMPUTER." computer_name"."|"SOURCE-COMPUTER." computer_name "WITH DEBUGGING MODE.") "OBJECT-COMPUTER."computer_name ("MEMORY SIZE" integer (words|characters|modules)|) ("PROGRAM COLLATING SEQUENCE IS" alphabet_name|) ("SEGMENT-LIMIT IS" segment_number|)"." ("SPECIAL-NAMES."(implementor_name("IS" mnemonic_name(("ON STATUS IS" condition_name("OFF STATUS IS"condition_name|)|)| ("OFF STATUS IS" condition_name("ON STATUS IS"condition_name|)|))| ("ON STATUS IS" condition_name("OFF STATUS IS"condition_name|))| ("OFF STATUS IS" condition_name("ON STATUS IS"condition_name|))|)|) (alphabet_name "IS"("STANDARD-1"|"NATIVE"|implementor_name| literal (("ALSO"literal("ALSO"literal|)|(("THROUGH"|"THRU") literal|))|)|(literal("ALSO"literal("ALSO"literal|) |(("THROUGH"|"THRU")literal|)|)|)|) ("CURRENCY SIGN IS" literal|) ("DECIMAL-POINT IS COMMA"|)"."|)
    5. input_output::= ("INPUT-OUTPUT SECTION." "FILE-CONTROL."#(file_control_entry) ("I-O-CONTROL."( "RERUN" ( "ON" (file_name|implementor_name)|) "EVERY"((("END OF"|)("REEL"|"UNIT")integer "RECORDS")"OF" file_name | ("MULTIPLE FILE TAPE CONTAINS" file_name("POSITION" integer|) (file_name("POSITION" integer|)|)|)|)|),

    6. File_Control_Entry::= "SELECT"("OPTIONAL"|) file_name "ASSIGN TO" implementor_name(implementor_name|) ("RESERVE" integer ("AREA"|"AREAS")|) ("ORGANIZATION IS SEQUENTIAL"|) ("ACCESS MODE IS SEQUENTIAL"|) ("FILE STATUS IS" data_name|)"." | "ASSIGN TO" implementor_name(implementor_name|) ("RESERVE" integer ("AREA"|"AREAS")|) ("ORGANIZATION IS RELATIVE"|) ("ACCESS MODE IS ("SEQUENTIAL"("RELATIVE KEY IS"data_name|)| ("FILE STATUS IS" data_name|)"." | "ASSIGN TO" implementor_name(implementor_name|) ("RESERVE" integer ("AREA"|"AREAS")|) ("ACCESS MODE IS ("SEQUENTIAL"|"RANDOM"|"DYNAMIC")|) "RECORD KEY IS" data_name ("ALTERNATE RECORD KEY IS" data_name("WITH DUPLICATES|)|) ("FILE STATUS IS" data_name|)"." | "SELECT" file_name "ASSIGN TO" implementor_name (implementor_name|),

    7. Data_Division::= ("FILE SECTION." Files (working_storage|)(linkage_section|).
    8. Files::=#(File_definition|Report_description|Sort_description).
    9. File_definition::=("FD" file_name ("BLOCK CONTAINS" (integer "TO"|) integer("RECORD"|""CHARACTERS")|) ("RECORD CONTAINS" (integer "TO"|) integer "CHARACTERS"|) "LABEL" ("RECORD IS"|"RECORDS ARE")("STANDARD"|"OMITTED") ("VALUE OF" implementor_name "IS" (data_name|literal) (implementor_name "IS" (data_name|literal) ("DATA" ("RECORD IS"|"RECORDS ARE") data_name #data_name|) #record_description_entry).
    10. Report_description::="RD" ("LINKAGE IS" (data_name|integer) "LINES" ("WITH FOOTING AT" (data_name|integer)|) ("LINES AT TOP" (data_name|integer)|)("LINES AT BOTTOM" (data_name|integer)|)|) ("CODE-SET IS" alphabet_name|) (("REPORT IS"|"REPORTS ARE") report_name #report_name"." #record_description_entry,
    11. Sort_description::="SD" file_name ("RECORD CONTAINS" (integer "TO"|) integer "CHARACTERS"|) ("DATA" ("RECORD IS"|"RECORDS ARE") data_name #data_name|)"." #record_description_entry.
    12. Working_storage_section::="WORKING-STORAGE SECTION." #(77_level_entry|record_description_entry)
    13. Linkage_sections::="LINKAGE SECTION." #(77_level_entry|record_description_entry),

    14. Data_Description_Entry::= level_number (data_name|"FILLER") ("REDEFINES" data_name|) (("PICTURE"|"PIC") ("IS"|) character_string|) (("USAGE IS"|)("COMPUTATIONAL"|"COMP"|"DISPLAY"|"INDEX")|) (("SIGN IS"|)("LEADING"|"TRAILING")("SEPARATE CHARACTER"|)|) ("OCCURS"(integer "TO" integer "TIMES DEPENDING ON" data_name| integer "TIMES") (("ASCENDING"|"DESCENDING") "KEY IS" data_name (index_name|)|)|) (("SYNCHRONIZED"|"SYNC") ("LEFT"|"RIGHT"|)|) (("JUSTIFIED"|"JUST") "RIGHT"|) ("BLANK WHEN ZERO"|) ("VALUE IS" literal|)"." | 66 data_name "REMAINS" data_name (("THROUGH"|"THRU") data_names|)"." | 88 condition_name ("VALUE IS"|"VALUES ARE") literal (("THROUGH"| "THRU") literal|) (literal(("THROUGH"|"THRU") literal|)|)".",

    15. Procedure_Division::= "PROCEDURE DIVISION ("USING" data_name ( data_name|)|)"." ("DECLARATIVES." (section_name "SECTION" (segment_number|)"." declarative_sentence (paragraph_name"." #(sentence|)|)) "END DECLARATIVES."|) #(section_name "SECTION" (segment_number|)"." #(paragraph_name"."#(sentence|)|)) | "PROCEDURE DIVISION ("USING" data_name ( data_name|)|)"." (paragraph_name"."(sentence|)),

    16. Accept_Verb::= "ACCEPT" identifier ("FROM" mnemonic_name|) | "ACCEPT" identifier "FROM" ("DATE"|"DAY"|"TIME") | "ACCEPT" name "MESSAGE COUNT",

    17. Add_Verb::= "ADD"sources ("TO" | "GIVING") #(identifier ("ROUNDED"|))size_exception | "ADD"("CORRESPONDING"|"CORR") identifier "TO" identifier ("ROUNDED"|) size_exception,

    18. Alter_Verb::= "ALTER" procedure_name "TO" ("PROCEED TO"|) procedure_name (procedure_name "TO" ("PROCEED TO"|) procedure_name|),

    19. Call_Verb::= "CALL" source ("USING" data_name (data_name|) overflow_exception,

    20. Cancel_Verb::= "CANCEL" source (identifier|literal|),

    21. Close_Verb::= "CLOSE" file_name(("REEL"|"UNIT")("WITH NO REWIND"|"FOR REMOVAL"|)|"WITH" ("NO REWIND"|"LOCK")|)(file_name(("REEL"|"UNIT")("WITH NO REWIND"| "FOR REMOVAL"|)|"WITH"("NO REWIND"|"LOCK")|)|) | "CLOSE" file_name ("WITH LOCK"|)(file_name("WITH LOCK"|)|),

    22. Compute_Verb::="COMPUTE" identifier "=" arithmetic_expression size_exception,

    23. Delete_Verb::= "DELETE" file_name "RECORD" ("INVALID KEY" imperative_statement|),

    24. Disable_Verb::= "DISABLE" ("INPUT" ("TERMINAL"|)|"OUTPUT") name "WITH KEY (identifier| literal),

    25. Display_Verb::= "DISPLAY" sources("UPON" mnemonic_name|),

    26. Divide_Verb::= "DIVIDE"source "INTO" identifier ("ROUNDED"|) (identifier ("ROUNDED"|)|)size_exception | "DIVIDE"source "INTO" source "GIVING" identifier ("ROUNDED"|) (identifier ("ROUNDED"|)|)size_exception | "DIVIDE"source "INTO" source "GIVING" identifier ("ROUNDED"|) "REMAINDER" (identifier ("ROUNDED"|)|)size_exception | "DIVIDE"source "BY" source "GIVING" identifier ("ROUNDED"|) "REMAINDER" (identifier ("ROUNDED"|)|)size_exception,

    27. Enable_Verb::= "ENABLE" ("INPUT" ("TERMINAL"|)|"OUTPUT") name "WITH KEY (identifier| literal),

    28. Enter_Verb::= "ENTER" language_name (routine_name|)".",

    29. Exit_Verb::= "EXIT" ("PROGRAM"|)".",

    30. Generate_Verb::= "GENERATE" (data_name|report_name),

    31. GoTo_Verb::= "GO TO" procedure_name | "GO TO" list(procedure_name) "DEPENDING ON" identifier,

    32. If_Verb::= "IF" condition (statement|"NEXT SENTENCE") ("ELSE" statement| "ELSE NEXT SENTENCE"),

    33. Initiate_Verb::= "INITIATE" list(report_name),

    34. Inspect_Verb::= "INSPECT" identifier "TALLYING" (identifier "FOR" (","|" "(("ALL"|"LEADING")source |"CHARACTERS")(("BEFORE"|"AFTER")" INITIAL" source|))) | "INSPECT" identifier "REPLACING" ("CHARACTERS BY")(identifier|literal(("BEFORE"|"AFTER")" INITIAL" source|) (","|" "("ALL"|"LEADING"|"FIRST")(","|" "source "BY" (identifier|literal(("BEFORE"|"AFTER")" INITIAL" source|)))),

    35. Replacing_Verb::= "REPLACING" " CHARACTERS BY")(source ("BEFORE"|"AFTER")" INITIAL" source|) | (","|" "("ALL"|"LEADING"|"FIRST")(","|" "source "BY" (identifier|literal(("BEFORE"|"AFTER")" INITIAL" source|)))),

    36. Merge_Verb::= "MERGE" file_name "ON" ("ASCENDING"|"DESCENDING") "KEY" list(data_name)("ON"("ASCENDING"|"DESCENDING") "KEY" list(data_name)("COLLATING SEQUENCE IS" alphabet_name|) "USING "list(file_name) ("OUTPUT PROCEDURE IS" section_name(("THROUGH"|"THRU")section_name|) |"GIVING" file_name),

    37. Move_Verb::= "MOVE" source "TO" list(identifier) | "MOVE"("CORRESPONDING"|"CORR") identifier "TO" identifier,

    38. Multiply_Verb::= "MULTIPLY" source "BY" targets size_exception | "MULTIPLY" source "BY" source "GIVING" targets size_exception,

    39. Open_Verb::= "OPEN"("INPUT" list(file_name ("REVERSED"|"WITH NO REWIND"))| "OUTPUT" list(file_name ("WITH NO REWIND"|))| "I-O" list(file_name)| "EXTEND" list(file_name) | "OPEN"list(("INPUT" | "OUTPUT" | "I-O")list( file_name) ),

    40. Perform_Verb::= "PERFORM" procedure_name(("THROUGH"|"THRU") procedure_name|) | "PERFORM" procedure_name(("THROUGH"|"THRU") procedure_name|) (identifier|integer)"TIMES" | "PERFORM" procedure_name(("THROUGH"|"THRU") procedure_name|) "UNTIL" condition | "PERFORM" procedure_name(("THROUGH"|"THRU") procedure_name|) "VARYING" (identifier|index_name) "FROM" (identifier|index_name)| literal)"BY"source"UNTIL" condition ("AFTER"(identifier|index_name) "FROM"(identifier|index_name| literal)"BY"source"UNTIL" condition ("AFTER"(identifier|index_name) "FROM"(identifier|index_name| literal)"BY"source"UNTIL" condition|)|),

    41. Read_Verb::= "READ" file_name "RECORD"("INTO" identifier|)(";"|" ""AT END" imperative_statement|) | "READ" file_name ("NEXT"|) "RECORD" ("INTO" identifier|) (";"|" ""AT END "imperative_statement|) | "READ" file_name "RECORD"("INTO" identifier|)(";"|" ""INVALID KEY " imperative_statement|) | "READ" file_name "RECORD"("INTO" identifier|)(";"|" ""KEY IS "data_name|) (";"|" ""INVALID KEY "imperative_statement|),

    42. Receive_Verb::= "RECEIVE" name ("MESSAGE"|"SEGMENT")" INTO" identifier (";"|" ""NO DATA " imperative_statement|),

    43. Return_Verb::= "RETURN" file_name "RECORD " ("INTO" identifier|) "; AT END "imperative_statement,

    44. Rewrite_Verb::= "REWRITE" record_name ("FROM "identifier|) | "REWRITE" record_name ("FROM "identifier|) (";"|" ""INVALID KEY "imperative_statement|),

    45. Search_Verb::= "SEARCH" identifier("VARYING "(identifier|index_name)|) (";"|" ""AT END" imperative_statement|) "; WHEN "condition (imperative_statement|" NEXT SENTENCE ") ("; WHEN "condition(imperative_statement|" NEXT SENTENCE ") "SEARCH ALL "identifier(";"|" ""AT END "imperative_statement|) "; WHEN (data_name ("IS EQUAL TO"|" IS =")(identifier|literal| arithmetic_expression)|condition_name)|) (imperative_statement|" NEXT SENTENCE"),

    46. Send_Verb::= "SEND" name "FROM" identifier | "SEND" name ("FROM" identifier|)("WITH"identifier| "WITH ESI"|"WITH EMI"|"WITH EGI")(("BEFORE"|"AFTER")"ADVANCING" (((identifier|integer)("LINE"|"LINES"|))|(mnemonic_name|"PAGE"))|),

    47. Set_Verb::= "SET"(list(identifier|index_name )("TO"|"UP BY"|"DOWN BUY") (identifier|index_name|integer),

    48. Sort_Verb::= "SORT" file_name "ON" ("ASCENDING"|"DESCENDING") "KEY" list(data_name )("ON" ("ASCENDING"|"DESCENDING") "KEY" list(data_name) )("COLLATING SEQUENCE IS "alphabet_name|) ("INPUT PROCEDURE IS "section_name((" THROUGH"|" THRU") section_name|)|"USING " list(file_name)) ("OUTPUT PROCEDURE IS "section_name((" THROUGH"|" THRU")section_name|)| "GIVING "file_name),

    49. Start_Verb::= "START "file_name ("KEY "("IS EQUAL TO"|"IS ="|"IS GREATER THAN"| "IS >"|"IS NOT LESS THAN"|"IS NOT <") data_name|) (";"|" ""INVALID KEY "imperative_statement|),

    50. Stop_Verb::= "STOP "("RUN "|literal),

    51. String_Verb::= "STRING "sources list(" DELIMITED BY "("SIZE"|sources) ))|) "INTO" identifier ("WITH POINTER " identifier|) overflow_exception,

    52. Subtract_Verb::= "SUBTRACT"(sources "FROM" targets | sources"FROM" source"GIVING" targets | identifer("CORRESPONDING"|"CORR") identifier "FROM" targets )size_exception,

    53. Suppress_Verb::= "SUPPRESS PRINTING"|"SUPPRESS",

    54. Terminate_Verb::= "TERMINATE " list(report_name),

    55. Unstring_Verb::= "UNSTRING " identifier ("DELIMITED BY "("ALL"|)source((","|" ")"OR"("ALL"|) source|)|)"INTO" identifier ((","|" ")"DELIMITER IN" identifier|)((","|" ")"COUNT IN" identifier|) ((","|" ")identifier((","|'" ")"DELIMITER IN" identifier|) ((","|" ")"COUNT IN" identifier|) ("WITH POINTER "identifier|)("TALLYING IN "identifier|) overflow_exception,

    56. Use_After_Verb::= "USE AFTER STANDARD "("EXCEPTION"|"ERROR") "PROCEDURE ON" (file_name#((","|" ")file_name|)|"INPUT"|"OUTPUT"|"I-O"| "EXTEND")".", Use_Before_Reporting_Verb::= "USE BEFORE REPORTING "identifier".",

    57. Use_For_Debugging_Verb::= "USE FOR DEBUGGING ON "(name|("ALL REFERENCES OF "identifier|)| file_name|procedure_name|"ALL PROCEDURES") ((","|" ")name|("ALL REFERENCES OF "identifier|)| file_name|procedure_name|"ALL PROCEDURES")".",

    58. Write_Verb::= "WRITE "record_name ("FROM "identifier|) (("BEFORE"|"AFTER")" ADVANCING"((identifier)("LINE"|"LINES"|)| (mnemonic_name|"PAGE"))|)("; AT"(" END-OF-PAGE"|"EOP") imperative_statement|) | "WRITE "record_name ("FROM "identifier|) ("; INVALID KEY "imperative_statement|),

    59. Relation_Condition::= (identifier|literal|arithmetic_expression|index_name) ("IS "("NOT"|)"GREATER THAN"|"IS "("NOT"|)"LESS THAN"| "IS "("NOT"|)"EQUAL TO"|"IS "("NOT"|)">"|"IS "("NOT"|)"<"| "IS "("NOT"|)"=")(identifier|literal|arithmetic_expression| index_name),

    60. Class_Condition::= identifier" IS"(" NOT"|)(" NUMERIC"|"ALPHABETIC"),

    61. Sign_Condition::= arithmetic_expression " IS"(" NOT"|)("POSITIVE"|"NEGATIVE"|"ZERO"),

    62. Condition_Name_Condition::= condition_name,

    63. Switch_Status_Condition::= condition_name,

    64. Negated_Simple_Condition::= "NOT" simple_condition,

    65. Combined_Condition::= condition(("AND"|"OR")condition),

    66. Abbreviated_Combined_Relation_Condition::= relation_condition#(("AND"|"OR")("NOT"|)(relation_operator|)object),

    67. Qualification::= (data_name|condition_name)(("OF"|"IN") data_name|)| paragraph_name(("OF"|"IN")section_name|)| text_name(("OF"|"IN") library_name|),

    68. Subscripting::= (data_name|condition_name)"("subscript((","|" ")subscript ((","|" ")subscript|)|)")",

    69. Indexing::= (data_name|condition_name)"("(index_name(("+"|"-") literal|) |literal)((","|" ")(index_name(("+"|"-") literal|)|literal) ((","|" ")(index_name(("+"|"-") literal|)|literal)|)|)")",

    70. Identifier_format::= data_name(("OF"|"IN")data_name|)("("subscript((","|" ")subscript ((","|" ")subscript|)|)")"|),

    71. Identifier_format::= data_name(("OF"|"IN")data_name|)("("(index_name(("+"|"-") literal|) |literal)((","|" ")(index_name(("+"|"-") literal|)|literal) ((","|" ")(index_name(("+"|"-") literal|)|literal)|)|)")"|),

    72. Copy_statement::= "COPY" text_name (("OF"|"IN") library_name|) ("REPLACING((","|" ")(==pseudotext==|identifier|literal|word) "BY"(==pseudotext==|identifier|literal|word))|),

    73. size_exception::=((";"|" ") ON SIZE ERROR" imperative_statement|).
    74. overflow_exception::=((";"|" ") "ON OVERFLOW" imperative_statement|).
    75. source::=identifier|literal.
    76. sources::=list(source).
    77. target::=identifier("ROUNDED"|),
    78. targets::=list(target),
    79. For X, list(X)::=X #((","|" ")X).

End