Cobol - 语法错误,意外的 $undefined,期待“文件结束”

Kar*_*rol 0 linux syntax cobol gnucobol

我在 cobol 中的语法有问题。我在 Ubuntu 4.2.0-16-generic 上使用 open-cobol 包,但出现错误:

~/cobol$ cobc -free -x -o cal cal.cbl
cal.cbl:6: Error: syntax error, unexpected $undefined, expecting "end of file"
Run Code Online (Sandbox Code Playgroud)

我的 cal.cbl 文件:

IDENTIFICATION DIVISION.
PROGRAM-ID. cal.
ENVIRONMENT DIVISION.

DATA DIVISION.   
?? OPTION PIC 9 VALUE ZERO.
?? NUM1   PIC 9(5)V9(2) VALUE ZERO.
?? NUM2   PIC 9(5)V9(2) VALUE ZERO.
?? RESULT PIC 9(10)V9(2) VALUE ZERO.

PROCEDURE DIVISION.
ACCEPT OPTION.

DISPLAY "INSERT FIRST OPTION".
ACCEPT NUM1.
DISPLAY "INSERT SECOND OPTION".
ACCEPT NUM2.

STOP RUN.
Run Code Online (Sandbox Code Playgroud)

我是 cobolt 的新手,我对列有所了解,这就是我使用 -free 标志进行编译的原因,但是这个错误对我来说没有意义。

为什么会出现这个错误,请帮忙:)

Sim*_*sch 5

??不是有效的 COBOL 字,也没有级别编号(第 6 行需要)。这些消息来自 OpenCOBOL/GnuCOBOL 1.1。

较新的 GnuCOBOL 版本在很多方面都要好得多,包括用户消息(这里是 GC 2.2):

cal.cob: 6: Error: Invalid symbol: ? - Skipping word
cal.cob: 6: Error: PROCEDURE DIVISION header missing
cal.cob: 6: Error: syntax error, unexpected Identifier
cal.cob: 7: Error: Invalid symbol: ? - Skipping word
cal.cob: 7: Error: syntax error, unexpected Identifier
cal.cob: 8: Error: Invalid symbol: ? - Skipping word
cal.cob: 8: Error: syntax error, unexpected Identifier
cal.cob: 9: Error: Invalid symbol: ? - Skipping word
cal.cob: 9: Error: syntax error, unexpected Identifier
cal.cob: 11: Error: syntax error, unexpected PROCEDURE
cal.cob: 12: Error: 'OPTION' is not defined
cal.cob: 15: Error: 'NUM1' is not defined
cal.cob: 17: Error: 'NUM2' is not defined
Run Code Online (Sandbox Code Playgroud)

更改??01or77并且您不再有错误。插入WORKING-STORAGE SECTIONLOCAL-STORAGE SECTION之后DATA DIVISION,您的程序编译良好。

获取程序员指南以了解有关 COBOL 的更多信息。