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

RE: gnubol: A question



Michael McKernan wrote the tome stuck on the end of this reply.

In Christopher's example, most compilers would (or should) fall over as 'Z' 
would be a duplicated name, regardless of the fact that it is a 
CONDITION-NAME. Compilation would fail during working-storage parse.

Now, to answer Michael's question. Arithmetic rules state that expression 
evaluation follows the 'BODMAS' rule i.e. evaluation is in the 
sequence		<B>rackets
					<O>f
					<D>ivision
					<M>ultiplication
					<A>ddition
					<S>ubtraction.

This being the case, then the second option is correct as in:

IF a = b OR ( c < d AND e < f ) OR a = g

In other words, the equation inside the brackets would be evaluated first. 
If c < d AND e < f, then the test would be:

	IF a = b OR {TRUE} OR a = g.

If, on the other hand, g is a CONDITION-NAME (as in Christopher's example) 
then the test would be:

	IF a = b OR {TRUE} OR {TRUE/FALSE}

Regards

Fred





>  for Randall Bart or whomever might have a defensible opinion.

>  I'm looking at how we might resolve the syntactic ambiguity of
>  abbreviated conditionals and condition names at parse time rather
>  than later in he compilation.  The problem was cited by Christopher
>  Clark and I have included the relevant part of his message at the end
>  of this one.

>  My question is really about abbreviated conditionals, apart from this
>  classic gotcha.  What effect do parenthesized expressions have on
>  abbreviation?  If I encounter the following
>
>  	 IF a = b OR ( c < d AND e < f ) OR g
>
>  and "g" is indeed a simple variable, should I interpret this to mean
>
>  	 IF a = b OR ( c < d AND e < f ) OR e < g
>
>  or perhaps

>  	 IF a = b OR ( c < d AND e < f ) OR a = g

>  or should it be diagnosed?  I've never been sure we've gotten this
>  one right in the past, evidenced by the fact that I can't remember
>  which way we did it.  I probably got an expert interpretation then,
>  but I need one again.
>
>  Thanks,
>
>  Mike



Christopher's example:

  ...

01  X PIC 9 VALUE 1.
01  Y PIC 9 VALUE 2.
*    88 Z VALUE 2.
01  Z PIC 9 VALUE 2.

PROCEDURE DIVISION.
MAIN.
    IF X = Y OR Z
        DISPLAY "s"
    ELSE
        DISPLAY "f"
    END-IF.

===========>8===============

    And point out that the IF statement _parses_ differently depending on 
which
version of Z is included, since as a field, the actual test is:

    (X = Y) OR (X = Z)

    <value1> = <value2> OR <value3>
        => <simple-condition> OR <value3>
        => <abbreviated-combined-condition>

    but if the 88 version is included, the actual test is:

    (X = Y) OR Z              =>        (X = Y) OR (Y = 2)

    ...






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


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