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

时间:2023-01-24 23:07:28

I have a problem with syntax in cobol. I'm using open-cobol package on Ubuntu 4.2.0-16-generic, and i've got error:

我在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"

My cal.cbl file:

我的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.

I'm new in cobolt, i know something about columns and thats why I'm using -free flag to compile, but this error have no sense for me.

我是cobolt的新手,我对列有所了解,这就是为什么我使用-free flag来编译,但这个错误对我没有意义。

Why this error occurs, please help:)

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

1 个解决方案

#1


4  

?? is no valid COBOL word and no level number (which is needed in line 6). GnuCOBOL 2.x is much better in many ways, including user messages:

??没有有效的COBOL字和没有级别编号(第6行需要)。 GnuCOBOL 2.x在很多方面都要好得多,包括用户消息:

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

Change ?? to 01 or 77 and you don't have the error any more. Insert WORKING-STORAGE SECTION or LOCAL-STORAGE SECTION after DATA DIVISION and your program compiles fine.

改变??到01或77,你不再有错误了。在DATA DIVISION之后插入WORKING-STORAGE SECTION或LOCAL-STORAGE SECTION,您的程序编译正常。

Get the Programmer's Guide for knowing more about COBOL.

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

#1


4  

?? is no valid COBOL word and no level number (which is needed in line 6). GnuCOBOL 2.x is much better in many ways, including user messages:

??没有有效的COBOL字和没有级别编号(第6行需要)。 GnuCOBOL 2.x在很多方面都要好得多,包括用户消息:

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

Change ?? to 01 or 77 and you don't have the error any more. Insert WORKING-STORAGE SECTION or LOCAL-STORAGE SECTION after DATA DIVISION and your program compiles fine.

改变??到01或77,你不再有错误了。在DATA DIVISION之后插入WORKING-STORAGE SECTION或LOCAL-STORAGE SECTION,您的程序编译正常。

Get the Programmer's Guide for knowing more about COBOL.

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