Topic
  • No replies
Gross
Gross
6 Posts

Pinned topic Implied subject in an IF statement

‏2012-04-09T16:23:12Z |
What does this expand to?
IF X NOT = ZERO AND + 100 GO TO Y.
Notice the space between the plus sign and the 100.
It is a legal instruction and used in production code.
Updated on 2012-04-19T19:48:56Z at 2012-04-19T19:48:56Z by brataj
  • brataj
    brataj
    40 Posts

    Re: Implied subject in an IF statement

    ‏2012-04-10T12:45:33Z  
    Interesting use of the unary + operator to confuse the reader.

    Otherwise the expression conforms to the Language Reference Manual section "6.1.6.14 Abbreviated combined relation conditions", in other words

    IF X NOT = ZERO AND X NOT = 100 GO TO Y.
  • rxross
    rxross
    5 Posts

    Re: Implied subject in an IF statement

    ‏2012-04-10T23:50:45Z  
    A unary operator is defined in the Enterprise COBOL for z/OS Language Reference as:

    "A plus (+) or a minus (-) sign that precedes a variable or a left parenthesis in an arithmetic expression and that has the effect of multiplying the expression by +1 or -1, respectively."

    So technically, the "+1" in

    "+1 space(s) numeric-literal"

    is part of the numeric-literal token. I guess the poster was questioning whether a space (or spaces) should be allowed between the left-most sign character (+,-) and a numeric literal token:

    "Only one sign character is allowed. If included, it must be the left most character of the literal. If the literal is unsigned, it is a positive value."
  • rxross
    rxross
    5 Posts

    Re: Implied subject in an IF statement

    ‏2012-04-10T23:54:56Z  
    • rxross
    • ‏2012-04-10T23:50:45Z
    A unary operator is defined in the Enterprise COBOL for z/OS Language Reference as:

    "A plus (+) or a minus (-) sign that precedes a variable or a left parenthesis in an arithmetic expression and that has the effect of multiplying the expression by +1 or -1, respectively."

    So technically, the "+1" in

    "+1 space(s) numeric-literal"

    is part of the numeric-literal token. I guess the poster was questioning whether a space (or spaces) should be allowed between the left-most sign character (+,-) and a numeric literal token:

    "Only one sign character is allowed. If included, it must be the left most character of the literal. If the literal is unsigned, it is a positive value."
    Small correction...

    A unary operator is defined in the Enterprise COBOL for z/OS Language Reference as:

    "A plus (+) or a minus (-) sign that precedes a variable or a left parenthesis in an arithmetic expression and that has the effect of multiplying the expression by +1 or -1, respectively."

    So technically, the "+" in

    "+ space(s) numeric-literal"

    is part of the numeric-literal token. I guess the poster was questioning whether a space (or spaces) should be allowed between the left-most sign character (+,-) and a numeric literal token:

    "Only one sign character is allowed. If included, it must be the left most character of the literal. If the literal is unsigned, it is a positive value."
  • brataj
    brataj
    40 Posts

    Re: Implied subject in an IF statement

    ‏2012-04-19T19:48:56Z  
    • rxross
    • ‏2012-04-10T23:54:56Z
    Small correction...

    A unary operator is defined in the Enterprise COBOL for z/OS Language Reference as:

    "A plus (+) or a minus (-) sign that precedes a variable or a left parenthesis in an arithmetic expression and that has the effect of multiplying the expression by +1 or -1, respectively."

    So technically, the "+" in

    "+ space(s) numeric-literal"

    is part of the numeric-literal token. I guess the poster was questioning whether a space (or spaces) should be allowed between the left-most sign character (+,-) and a numeric literal token:

    "Only one sign character is allowed. If included, it must be the left most character of the literal. If the literal is unsigned, it is a positive value."
    <hat type="legal">Actually that's just a quote from the glossary, and therefore isn't binding on the compiler...</hat>

    In any case, the sign on a literal is, unlike in some other languages, part of the literal rather than a unary operator. For example this is ok

    IF X NOT = ZERO AND + +100 GO TO Y.

    but this is not:

    IF X NOT = ZERO AND + + 100 GO TO Y.

    and produces a IGYPS2049-E Consecutive unary signs (sic) were used in an arithmetic statement.