Why does COBOL have to be indented? [closed]

只谈情不闲聊 提交于 2021-01-26 20:49:56

问题


Why does COBOL have to be indented, as in, have additional spacing in each sourcefile?

Consider this code (note the additional whitespace):

  IDENTIFICATION DIVISION.
  PROGRAM-ID. HELLO-WORLD.
  PROCEDURE DIVISION.
      DISPLAY 'Hello, world'.
      STOP RUN.

A similar formatting can be seen in Fortran code:

   program hello
      print *, "Hello World!"
   end program hello

But why do COBOL and Fortran need this whitespace? What's the reason?


回答1:


Cobol no longer has to be indented. AFAIK, all most modern compilers support format free Cobol source.

The original reason was dealing with punch cards. Cobol kept the first 6 positions for a line sequence number. Column 7 was a continuation / comment / debug / form-feed. Area "A", or Columns 8-11, indicated certain special language artifacts like 01 levels, section or paragraph names, et al. Area "B", or Columns 12 - 72, was for open code. Columns 73 - 80 were for OS sequence numbers.

The two languages you mention, Cobol and Fortran, were both written before automatic parser generation existed. And they had no real prior art to draw on for good and bad ideas of how to create parse-able source text. So some of the things -- like Area "A" for special section headers -- made the task of manually writing parsers easier. Modern languages tend to use context free grammars to make parser generation simple. But that postdates Cobol.



来源:https://stackoverflow.com/questions/8959489/why-does-cobol-have-to-be-indented

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!