[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [GNU-COBOL] Yet Another Grammar question



Laura Tweedy wrote:

> Okay, my next grammar question concerns my interpretation of the
> definition of "imperative statement".
>
> First, the standard (page IV-39) says:
> An imperative statement begins with an imperative verb and specifies an
> unconditional action to be taken by the object program or is a
> conditional statement that is delimited by its explicit scope terminator
> (delimited scope statement).
>
> Is this saying that only the conditional statement is delimited by a
> scope terminator, or is it that both imperatives and conditionals are
> delimited?

The imperative statement, which can be composed of multiple imperative
statements, is terminated by the separator period.  Delimiters between the
imperative statements are permitted but not necassary, this delimiter is the
semicolon or comma. But see also the last alinea with the exeptions on the
terminator point.

> Second, the standard on the same page says:
> An imperative statement may consist of a sequence of imperative
> statements, each possibly separated from the next by a separator.
>
> What, then, is the difference between a statement and a sentence?  Does
> a sentence in this case require a separator?  Is the separator above
> necessarily a period, or does it also include END-ADD and such?

A sentence is composed of one or more statements. The wording in the standard is
indeed confusing.
Only the sentence needs the separator point.
END-ADD belongs to the COBOL-85 dialect and was not considered for now (if I
remember well), but that's not what you asked. The END-ADD can be included. But
conditional clauses in unconditional statements are NOT permitted, so the
SIZE ERROR, INVALID KEY, ON OVERFLOW and AT END clauses are prohibited.

> Third, I read the rest of this section to say that if we have nested
> imperatives, such as:
>
> ADD 5 TO FOO
>         ON SIZE ERROR ADD 3 TO BAR

Nested imperative statements in COBOL don't exist : it ends with the period (but
see below).

> But, if the answer to my first question is, no, we don't need a closing
> delimiter, and since and "imperative statement" can be more than one
> statement, how would we differentiate between more imperative statements
> and those that should logically follow the original ADD?
>
> For example, how do we interpret:
>
> ADD 5 TO FOO
>         ON SIZE ERROR ADD 3 TO BAR
>                       ACCEPT BAZ
>                       ADD 9 TO OTHER

The  ADD 3 TO BAR
    ACCEPT BAZ
    ADD 9 TO OTHER
are only executed if the SIZE ERROR condition is triggered.

> Based on this ambiguity, I'm inclined to believe that some kind of
> delimiter is required at the end of the "imperative statement".
>
> But, since "NOT ON SIZE ERROR" cannot occur within one of the nested
> ADDs, we can write the following without any ambiguity or explicit
> delimiters on the "imperative statement":
>
> ADD 5 TO FOO
>         ON SIZE ERROR ADD 3 TO BAR
>                       ACCEPT BAZ
>                       ADD 9 TO OTHER
>         NOT ON SIZE ERROR PERFORM SOME-PAR

As you see above the PERFORM is executed when the SIZE ERROR condition is NOT
triggered.

In the wording of the BULL GCOS-7 COBOL Reference Manual :

"Whenever 'imperative statement' appears in the General Format of statements [in
the Procedure Division], 'imperative statement' refers to that sequence of
consecutive imperative statements that must be ended by a period or an ELSE
phrase associated with a previous IF statement or a WHEN phase associated with a
previous SEARCH statement."
In COBOL-85 the imperative statement can also be ended by the END-ADD clause.
Regards,

Fred Mobach
fred@mobach.nl



--
This message was sent through the gnu-cobol mailing list.  To remove yourself
from this mailing list, send a message to majordomo@acm.cs.umr.edu with the
words "unsubscribe gnu-cobol" in the message body.  For more information on
the GNU COBOL project, send mail to gnu-cobol-owner@acm.cs.umr.edu.