Code Comments
Programming Forum and web based access to our favorite programming groups.As some of you may recall, I'm trying to write a tool to process COBOL programs in general, so I'm not working with any one particular compiler or operating system. While trying to parse these COBOL programs, it looks like the clauses of a PERFORM statement can be re-ordered (because the COBOL programs distributed with the NIST test suite do so), even though the language specs I'm looking at (Liant RM/COBOL) doesn't make any mention of this. To be specific, I'm looking at PERFORM statements that refer to a specific paragraph (i.e. not inlined statements), and I'm with the VARYING variant. I've seen PERFORM VARYING statements following these two structures: PERFORM <ProcedureRange> [ <PerformTestPositionClause> ] <PerformVaryingClause> ( <PerformAfterClause> )* and PERFORM [ <PerformTestPositionClause> ] <PerformVaryingClause> ( <PerformAfterClause> )* <ProcedureRange> Where the [] symbols mean that that clause is optional, and the ()* means that that clause can appear zero or more times (i.e. arbitrarily many times). ProcedureRange looks like: <ProcedureName> [ ( THROUGH | THRU ) <ProcedureName> ] PerformTestPositionClause looks like: [ WITH ] TEST ( BEFORE | AFTER ) PerformVaryingClause looks like: VARYING <Identifier> <FromPhrase> BY ( <Identifier> | <Literal> ) <PerformUntilClause> PerformAfterClause looks like: AFTER <Identifier> <FromPhrase> BY ( <Identifier> | <Literal> ) <PerformUntilClause> As a concrete example, the two formats might look like: PERFORM MY-PARAGRAPH VARYING FOO FROM 1 BY 1 UNTIL FOO > 5 versus PERFORM VARYING FOO FROM 1 BY 1 UNTIL FOO > 5 MY-PARAGRAPH Anyway, so my question is, does it affect the semantics of the program the fact that sometimes <ProcedureRange> appears as the first clause and other times as the last clause? - Oliver
Post Follow-up to this messageTop post, going to the example: > PERFORM MY-PARAGRAPH VARYING FOO FROM 1 BY 1 UNTIL FOO > 5 > > versus > > PERFORM VARYING FOO FROM 1 BY 1 UNTIL FOO > 5 MY-PARAGRAPH That's not quite it. In the first example, which is OK, MY-PARAGRAPH exists somewhere else in the program -- could be before, could be after -- the PERFORM statement. This is denoted an "out-of-line PERFORM" in the COBOL standards. Thus, the aggregate looks like this: PERFORM MY-PARAGRAPH VARYING FOO FROM 1 BY 1 UNTIL FOO > 5 .. <end of the paragraph in which the PERFORM exists> MY-PARAGRAPH. <some code that gets performed> ANOTHER-PARAGRAPH. ... The second example actually isn't valid standard COBOL as written; what I think you're trying to get at is an "inline PERFORM" as described in the standards: PERFORM VARYING FOO FROM 1 BY 1 UNTIL FOO > 5 <some code that gets performed> END-PERFORM ... [Note that in the latter case both EXIT PERFORM and EXIT PERFORM CYCLE are allowed -- but not required -- within <some code that gets performed>, but not in the former.] In the case that the code within <some code that gets performed> is the same, the effect is the same; in other words, for a given <some code that gets performed> these are two valid ways to accomplish the desired task according to standard COBOL. -Chuck Stevens "Oliver Wong" <owong@castortech.com> wrote in message news:ZEYTe.166447$wr.33839@clgrps12... > As some of you may recall, I'm trying to write a tool to process COBOL > programs in general, so I'm not working with any one particular compiler or > operating system. While trying to parse these COBOL programs, it looks like > the clauses of a PERFORM statement can be re-ordered (because the COBOL > programs distributed with the NIST test suite do so), even though the > language specs I'm looking at (Liant RM/COBOL) doesn't make any mention of > this. > > To be specific, I'm looking at PERFORM statements that refer to a > specific paragraph (i.e. not inlined statements), and I'm with the VARYING > variant. I've seen PERFORM VARYING statements following these two > structures: > > PERFORM > <ProcedureRange> > [ <PerformTestPositionClause> ] > <PerformVaryingClause> > ( <PerformAfterClause> )* > > and > > PERFORM > [ <PerformTestPositionClause> ] > <PerformVaryingClause> > ( <PerformAfterClause> )* > <ProcedureRange> > > Where the [] symbols mean that that clause is optional, and the ()* > means that that clause can appear zero or more times (i.e. arbitrarily many > times). > > ProcedureRange looks like: > <ProcedureName> [ ( THROUGH | THRU ) <ProcedureName> ] > > PerformTestPositionClause looks like: > [ WITH ] TEST ( BEFORE | AFTER ) > > PerformVaryingClause looks like: > VARYING <Identifier> <FromPhrase> BY ( <Identifier> | <Literal> ) > <PerformUntilClause> > > PerformAfterClause looks like: > AFTER <Identifier> <FromPhrase> BY ( <Identifier> | <Literal> ) > <PerformUntilClause> > > As a concrete example, the two formats might look like: > > PERFORM MY-PARAGRAPH VARYING FOO FROM 1 BY 1 UNTIL FOO > 5 > > versus > > PERFORM VARYING FOO FROM 1 BY 1 UNTIL FOO > 5 MY-PARAGRAPH > > Anyway, so my question is, does it affect the semantics of the program > the fact that sometimes <ProcedureRange> appears as the first clause and > other times as the last clause? > > - Oliver > >
Post Follow-up to this message
"Oliver Wong" <owong@castortech.com> wrote in message
news:ZEYTe.166447$wr.33839@clgrps12...
> As some of you may recall, I'm trying to write a tool to process COBOL
> programs in general, so I'm not working with any one particular compiler
or
> operating system. While trying to parse these COBOL programs, it looks
like
> the clauses of a PERFORM statement can be re-ordered (because the COBOL
> programs distributed with the NIST test suite do so), even though the
> language specs I'm looking at (Liant RM/COBOL) doesn't make any mention of
> this.
Could you provide an actual example from the NIST suite that illustrates
this?
In standard COBOL, if the perform range is elsewhere (that is, in a
different paragraph) the perform range is specified *immediately following*
the PERFORM keyword. If there's no paragraph-name immediately following the
PERFORM keyword, that identifies the statement as an inline PERFORM. There
are, as I see it, no other choices.
The formats in the '85 standard are a little confusing on this issue,
conflating as they do the "in-line" and "out-of-line" PERFORM formats.
The '02 standard clarifies this considerably (the following is a summary,
not an exact reproduction):
Format 1 (out-of-line):
PERFORM procedure-name-1 [{THROUGH/THRU} procedure-name-2 ]
[times-phrase / until-phrase / varying-phrase]
Format 2 (in-line):
PERFORM [times-phrase / until-phrase / varying-phrase]
imperative-statement-1 END-PERFORM
So far as I know, this change of format itself is not considered a
significant change, though the allowing of AFTER in an inline perform and
the use of common exit points for multiple PERFORMs is noted.
-Chuck Stevens
Post Follow-up to this message"Chuck Stevens" <charles.stevens@unisys.com> wrote in message news:dfpr5m$25jm$1@si05.rsvl.unisys.com... > > "Oliver Wong" <owong@castortech.com> wrote in message > news:ZEYTe.166447$wr.33839@clgrps12... > or > like > > Could you provide an actual example from the NIST suite that illustrates > this? I was afraid of being asked for this... <sheepish grin> The fact is that I don't know for sure that the re-ordered phrases variant of the PERFORM statement ever appears in the NIST test suite, but I had strongly suspect that it did, mainly because I had implemented support for that variant in my parser. I'm also in the middle of some significant changes in the program, so it's not easy for me to simply try removing support for that variant, re-parsing the NIST suite and see which programs fail to parse, though I may be able to try that again in a few ws. Thanks for mentioning in the other branch of this thread, BTW, that the second variant is not standard COBOL. This indirectly answers my original question. - Oliver
Post Follow-up to this messageOliver Wong wrote: > PERFORM MY-PARAGRAPH VARYING FOO FROM 1 BY 1 UNTIL FOO > 5 > > versus > > PERFORM VARYING FOO FROM 1 BY 1 UNTIL FOO > 5 MY-PARAGRAPH I'll have to try it and see. I must say, though, if I saw that in my shop, I'd slap the programmer (at least figuratively). If the compiler took it... Well, I betting it doesn't, but we'll see. :) (My guess is that the compiler is going to interpret "Perform Varying" as an inline perform, and "MY-PARAGRPH" is going to be flagged as "not legal in this position.) -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~ ~ / \ / ~ Live from Montgomery, AL! ~ ~ / \/ o ~ ~ ~ / /\ - | ~ daniel@thebelowdomain ~ ~ _____ / \ | ~ http://www.djs-consulting.com ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ GEEKCODE 3.12 GCS/IT d s-:+ a C++ L++ E--- W++ N++ o? K- w$ ~ ~ !O M-- V PS+ PE++ Y? !PGP t+ 5? X+ R* tv b+ DI++ D+ G- e ~ ~ h---- r+++ z++++ ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~
Post Follow-up to this messageLX-i wrote: > Oliver Wong wrote: > > > > I'll have to try it and see. I must say, though, if I saw that in my > shop, I'd slap the programmer (at least figuratively). If the compiler > took it... Well, I betting it doesn't, but we'll see. :) > > (My guess is that the compiler is going to interpret "Perform Varying" > as an inline perform, and "MY-PARAGRPH" is going to be flagged as "not > legal in this position.) Well I tried it with Realia COBOL educational version 1.00 (probably based on Realia 3.0, circa 1990, but it compiles in DosBOX 6.3 and programs execute in WinXP command line window). Here's the sample program: IDENTIFICATION DIVISION. PROGRAM-ID. hello. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 FOO PIC 9(4) VALUE ZERO. PROCEDURE DIVISION. MAINLINE. DISPLAY "hello ,". DISPLAY "world!". PERFORM VARYING FOO FROM 1 BY 1 UNTIL FOO > 5 MY-PARAGRAPH. STOP RUN. MY-PARAGRAPH. DISPLAY "FOO = " FOO. And it wouldn't compile clean. Gave me an E-level diagnostic on line 13 for "Unrecognizable word or literal 'MY-PARAGRAPH'" I suspect it would not compile on Enterprise COBOL for z/OS, but I have not tried this code on that compiler. -- http://arnold.trembley.home.att.net/
Post Follow-up to this message"Arnold Trembley" <arnold.trembley@worldnet.att.net> wrote in message news:KCvUe.27444$qY1.24766@bgtnsc04-news.ops.worldnet.att.net... [snip sample program] > And it wouldn't compile clean. Gave me an E-level diagnostic on line 13 > for "Unrecognizable word or literal 'MY-PARAGRAPH'" > > I suspect it would not compile on Enterprise COBOL for z/OS, but I have > not tried this code on that compiler. Okay, thank you. I guess I'll just have to try removing support for this construct, re-run the tests and see what (if anything) breaks. ;) - Oliver
Post Follow-up to this message"Oliver Wong" <owong@castortech.com> wrote in message news:UigVe.238674$tt5.7451@edtnps90... > Okay, thank you. I guess I'll just have to try removing support for > this construct, re-run the tests and see what (if anything) breaks. ;) I removed support for the non-standard construct, and it seems all the files parsed properly. I guess I must have been distracted while implementing that part of the grammar. Thank you, everyone. Problem is now resolved. - Oliver
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.