6

Most modern programming languages give a way to add inline comments, generally those that use a newline character to indicate the end of a comment, and an arbitrary delimiter or sequence of tokens to indicate the beginning of a comment, while letting the beginning of the line being an interpreted instruction.

In COBOL, while commenting a whole line is well documented (it can be done by putting an asterisk symbol (*) in column 7), finding documentation on whether or not you can comment the rest of the line beginning at an arbitrary position is harder.

The question is: can you comment the rest of a line beginning at an arbitrary position in COBOL?

Imagining that # is the special character for this kind of comment, here is a fictive example of what is seeked:

   *--- This structure is a dummy example
    01 MY-STRUCTURE.
        05 MY-VARIABLE PIC X VALUE '-'. # Valid values are in {-, a, b}
4

4 回答 4

10

Pre Cobol 2002 否

在 Cobol 2002 中引入了 *>。请参阅Cobol 2002并搜索内联注释,其中给出了以下示例:

05 Field-X Pic XX *> Used in calculating the current THINGY
...
MOVE ABC to XYZ  *> Current-XYZ
             LMN *> Saved XYZ

还有其他一些例外

  • Exec Sql - End-Exec中。对于某些 SQL 供应商(例如 Oracle),您可以使用内嵌注释 (/* */)。这不是真正的 Cobol,而是一种嵌入式语言,通常通过预编译器实现。Othere Exec End-exec 语句也可以允许内联注释。
  • 可能还有其他允许行注释的 Cobols 实现
  • 默认情况下,许多 Cobol 20002 之前的编译器只查看第 7 到 72列。所以第 1 到 6列以及第 71 列之后的任何内容都可以包含注释。
于 2013-07-12T13:36:09.263 回答
6

Enterprise COBOL V5.1将支持内联注释

发布亮点

引入浮动注释指示符以在程序文本区域的任何位置创建注释 Enterprise COBOL for z/OS,V5.1 引入了浮动注释指示符('*>')。

您可以在程序文本区域的任何位置指定它,以指示一行上的后续文本是注释行或内联注释。

如果浮动注释指示符是程序文本区域(区域 A 加区域 B,第 8 - 72 列)中的第一个字符串,则表示注释行,如果它位于程序文本区域中的一个或多个字符串之后,则指示内联注释。程序文本区。

于 2013-07-12T13:59:03.347 回答
6

不,但是当您将代码提交给编译器时,您可以编写一个程序来“包装”您的代码。我们在 20 年前就这样做了。

例如。

   SOME COBOL CODE  -- DOUBLE DASH INDICATES COMMENT TO END OF LINE

然后编写一个程序来查找双破折号并让它删除 -- 和文本。然后在你编译的 jcl 中,将你的源代码输入到程序中,然后输出到编译器。简单的。使用 INSPECT 语句。

 INSPECT LINE, TALLYING CHARACTERS BEFORE INITIAL "--".
 MOVE SPACES TO LINE(TALLY:),

就是这样。删除注释并发送给编译器。

于 2013-07-12T20:03:47.587 回答
3

COBOL 文档。开放,免费。

在有限的时间内,虽然它仍然是草稿并开放征求意见

当 COBOL 20xx 草案成为批准的 ISO 标准时,最后一个链接几乎肯定会过期,并且除了来自 ISO PL22 WG4 源之外,它实际上并不是为了重新分发。

COBOL 支持 FIXED 和 FREE 源代码格式。FIXED 较旧,基于 80 个列卡,其中 1 到 6 列用于序列号,7 列用于指令,第 8 到 72 列用于程序文本。

第 7 列中的星号是固定形式的 COBOL 注释行。

OCOBOL* Sequence number field "OCOBOL" in this case, it can be anything
      * and comment line indicator

      *> inline comment, can be used for FREE format COBOL, as well as FIXED.

有个窍门;将星号放在第 7 列中,将大于号放在第 8 列中,您就有了一个可以在固定格式和自由格式 COBOL 中使用的注释行。

对于将遵循草案 20xx 和

>>

指令,还有另一个技巧可以帮助 FIXED/FREE 源编译支持。

123456
    >>D free format debug line directives

如果 D 在第 7 列中,并且在 5 和 6 中有两个大于,则您也混合了对调试行的 FIXED 和 FREE 源文本支持。

于 2013-07-15T23:35:14.700 回答