开发者

Are Commas only used in a picture clause within Cobol

I'm working from this parser http://mapage.noos.fr/~bpinon/cobol.jj and trying to get pictures to work with com开发者_如何转开发mas. It seems to just support commas out of the picture string as a separator. Just wondering where else commas are used in Cobol.

Cheers


COBOL has several separators. A comma followed by a space is one of them. However, a comma not followed by a space, as you may find in PICTURE strings, is not a separator but part of the PICTURE string. The rules for COBOL separators are not all that complex. Note that periods, commas and semicolons when followed by a space are always separators. Strictly speaking, the space is necessary but several compilers (IBM Enterprise COBOL for z/OS for example) are often capable of recognizing commas, periods and semicolons not followed by a space as separators based on the context that they appear in (a warning may be issued but a valid object module is still generated).

To answer your specific question: A separator comma can appear anywhere a blank space can appear. A comma within the context of a PICTURE string is significant and is not treated as a spearator (ie. it cannot be followed by a blank space).

It may be usefull to note that a COBOL PICTURE strings are delimited only by the separator space, separator comma, separator semicolon, or separator period.

When building a robust COBOL parser you will soon recognize that there are three areas of a COBOL source text (after the "text manipulation" phase has been completed) that require special attention.

  • COMMENT Entries. These are depreciated but still commonly found in many programs
  • PICTURE Strings
  • Everything else

The "Everything else" chunk constitutes the bulk of a source file, the tendency is to focus on parsing that while pretty much ignoring the other two items. However, PICTURE strings are actually fairly complex entities to deal with. COMMENT Entries are just silly and could potentially be removed during Text Manipulation.

Before you get too deep into this, recognize that the grammar you are working with is only designed to recognize COBOL source text after what is commonly known as "text manipulation" has been completed. This is a pre-step where COPY/REPLACE directives are expanded, continuation lines are dealt with and a number of other COMPILER directing statements are processed. Do not underestimate the work needed to perform this step.

Building a robust parser for COBOL is a truly daunting task. It can take years to get right. Partly because the language was not designed to be parsed using what have since become "industry" standard parsing techniques and partly because every COBOL compiler vendor has its own set of idiosyncratic variances to the standard.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜