这是我为COBOL类做的示例程序,我在尝试通过命令行编译时遇到的错误代码有几个问题。请看下面。 COBOL下方将是我的终端代码。如何修复"意外的标识符?"
IDENTIFICATION DIVISION.
PROGRAM-ID. SAMPLE135.
AUTHOR. ME.
ENVIRONMENT DIVISION.
DATA DIVISION.
77 FIELD-A PIC 9(2).
77 FIELD-B PIC 9(2).
77 FIELD-C PIC 9(3) VALUE ZERO.
77 FIELD-D PIC 9(3) VALUE ZERO.
WORKING-STORAGE SECTION.
PROCEDURE DIVISION.
FIRST-PARAGRAPH.
MOVE ZEROS TO FIELD-A FIELD-B.
PERFORM SECOND-PARAGRAPH.
PERFORM THIRD-PARAGRAPH.
PERFORM SECOND-PARAGRAPH.
PERFORM WRITE-DATA.
STOP RUN.
SECOND-PARAGRAPH.
ADD 10 TO FIELD-A.
ADD 20 TO FIELD-B.
THIRD-PARAGRAPH.
MULTIPLY FIELD-A BY FIELD-B GIVING FIELD-C.
DIVIDE FIELD-A INTO FIELD-B GIVING FIELD-D.
WRITE-DATA.
DISPLAY FIELD-A.
DISPLAY FIELD-B.
DISPLAY FIELD-C.
DISPLAY FIELD-D.
END PROGRAM.
Sample2.cbl:9: Error: syntax error, unexpected "Identifier", expecting "end of file"
答案 0 :(得分:4)
你有'77'数据项在错误的地方,也缩进。还要确保字段名称以区域B 开头(除非使用自由格式)。尝试
DATA DIVISION.
WORKING-STORAGE SECTION.
77 FIELD-A PIC 9(2).
77 FIELD-B PIC 9(2).
77 FIELD-C PIC 9(3) VALUE ZERO.
77 FIELD-D PIC 9(3) VALUE ZERO.
在Cobol代码中,通常认为只使用'。'会更好。当他们绝对需要时(在程序之前),即
SECOND-PARAGRAPH.
ADD 10 TO FIELD-A
ADD 20 TO FIELD-B
.
THIRD-PARAGRAPH.
最后,它也是标准练习缩进 TO 和 PIC 语句 因为我有
答案 1 :(得分:1)
WORKING-STORAGE SECTION标题必须在77级定义之前。
print new_array
['hello','what?',u'is',u'going',u'on?']
您还错过了结束标记中的程序名称。
DATA DIVISION.
WORKING-STORAGE SECTION.
77 FIELD-A PIC 9(2).
77 FIELD-B PIC 9(2).
77 FIELD-C PIC 9(3) VALUE ZERO.
77 FIELD-D PIC 9(3) VALUE ZERO.