COBOL LINUX – 在编译时收到错误。

huangapple go评论73阅读模式
英文:

COBOL LINUX - when compiling, receiving errors

问题

在尝试编译时,我遇到了如下所示的多个错误:

user@DESKTOP-57BGLNH:~$ pwd
/home/user
user@DESKTOP-57BGLNH:~$ ls
COBOL               testdoc.cob
user@DESKTOP-57BGLNH:~$ cobc -x testdoc.cob
assignment1.cob:1: error: invalid indicator 'f' at column 7
assignment1.cob:2: error: invalid indicator 'm' at column 7
assignment1.cob:4: error: invalid indicator 'n' at column 7
assignment1.cob:5: error: invalid indicator 'u' at column 7
assignment1.cob:7: error: invalid indicator 'i' at column 7
assignment1.cob:8: error: invalid indicator 'g' at column 7
assignment1.cob:10: error: invalid indicator 'u' at column 7
assignment1.cob:11: error: invalid indicator 'a' at column 7
assignment1.cob:12: error: invalid indicator 'k' at column 7
assignment1.cob:14: warning: line not terminated by a newline [-Wothers]
assignment1.cob:14: error: invalid indicator 'r' at column 7
assignment1.cob:9: error: PROGRAM-ID header missing
assignment1.cob:9: error: PROCEDURE DIVISION header missing
assignment1.cob:9: error: syntax error, unexpected PICTURE
user@DESKTOP-57BGLNH:~$

*为了提供背景信息,

我在 Visual Studio Code (VSC) 中,打开了远程窗口,并创建了一个包含以下代码的新文件:

identification division.
program-id. Assignment1.

environment division.
configuration section.

data division.
working-storage section.
01 out pic x(11) value "Hello World".
procedure division.
    display out.
    goback.
end program Assignment1.

然后,我打开了一个新终端,并使用 pwdls 命令确保我在正确的目录中。如你所见,"/home/user" 是包含文件 "testdoc.cob" 的目录,根据 ls 命令。接着,我使用命令 cobc -x testdoc.cob 进行编译,然后出现了上述一系列错误。为什么会出现这些错误?我在哪里出错了?

我尝试在不同的文件夹中重复这个过程,使用不同的扩展名,但结果都相同。

英文:

When attempting to compile I get these numerous errors as seen below:

user@DESKTOP-57BGLNH:~$ pwd
/home/user
user@DESKTOP-57BGLNH:~$ ls
COBOL               testdoc.cob
user@DESKTOP-57BGLNH:~$ cobc -x testdoc.cob
assignment1.cob:1: error: invalid indicator 'f' at column 7
assignment1.cob:2: error: invalid indicator 'm' at column 7
assignment1.cob:4: error: invalid indicator 'n' at column 7
assignment1.cob:5: error: invalid indicator 'u' at column 7
assignment1.cob:7: error: invalid indicator 'i' at column 7
assignment1.cob:8: error: invalid indicator 'g' at column 7
assignment1.cob:10: error: invalid indicator 'u' at column 7
assignment1.cob:11: error: invalid indicator 'a' at column 7
assignment1.cob:12: error: invalid indicator 'k' at column 7
assignment1.cob:14: warning: line not terminated by a newline [-Wothers]
assignment1.cob:14: error: invalid indicator 'r' at column 7
assignment1.cob:9: error: PROGRAM-ID header missing
assignment1.cob:9: error: PROCEDURE DIVISION header missing
assignment1.cob:9: error: syntax error, unexpected PICTURE
user@DESKTOP-57BGLNH:~$ 

*For context,

I am in VSC, I open the remote window and create a new file with the following code:

identification division.
program-id. Assignment1.

environment division.
configuration section.

data division.
working-storage section.
01 out pic x(11) value "Hello World".
procedure division.
    display out.
    goback.

end program Assignment1.

File> Save.

Open new terminal, and use pwd and ls to ensure I am in the right directory, as you can see "/home/user" is the directory where file "testdoc.cob" is located, as per ls command. I then use "cobc -x testdoc.cob" to compile, and then I get these series of errors. Why is this? and where am I going wrong?

Ive tried repeating the process in new folders with different .extentions, all end in the same result.

答案1

得分: 1

这是COBOL编程中关于代码格式的内容。COBOL2002标准引入了自由格式的参考格式,其中有一列"sequence"在1-6列,指示符在第7列,根据使用的标准,代码可以在12-72列之间或包括8-11列(以前只有一些声明在此列)。对于一些仍然仅支持这种格式的COBOL工具,你可能仍然考虑在新代码中使用它。在团队中编写代码时,通常会有关于使用哪种格式的规定。

要了解更多关于这些格式的信息,可以查看你使用的编译器的程序员指南

GnuCOBOL 3.2使用以下命令进行编译:

> assignment.cob:1: note: free format detected

对于早期版本,你可以通过传递命令行选项--free来显式设置它,或者如程序员指南中所述,使用编译器指令:

>> SOURCE FORMAT IS FREE

(此指令从第8列开始)。Micro Focus COBOL(在PC上有相当大的市场份额)将其定义为:

$SET SOURCE-FORMAT "FIXED"

(GnuCOBOL支持两者)。

英文:

This is code in free-form reference-format, which was standardized with COBOL2002, the "historical" fixed-form reference-format uses a layout in which there is a "sequence" column 1-6, an indicator column 7 and depending on the standard used the code goes to column 12-72 or also includes 8-11 (where previously only some declarations went).
"Old" code you see will be often in fixed-form reference-format and as some COBOL tools still only support this format, you may consider still using it for new code. When coding in a group (or a "COBOL shop") you will commonly have rules about what to use.

To learn more about formats see the Programmer's Guide for the compiler you use.

GnuCOBOL 3.2 compiles this with

> assignment.cob:1: note: free format detected

for earlier versions either explicit set it by passing the command line option --free or, as noted in the Programmer's Guide, use a compiler directive:

       >> SOURCE FORMAT IS FREE

(that starts in column 8) is the COBOL standard way to set this, Micro Focus COBOL (which has quite a big market in COBOL on PC) defines it as:

       $SET SOURCE-FORMAT "FIXED"

(GnuCOBOL supports both)

huangapple
  • 本文由 发表于 2023年3月7日 08:48:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/75657121.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定