Skip to main content

module lang::cobol85::\syntax::Condition

rascal-0.43.3
org.rascalmpl.cobol-air-0.1.2

Conditions: sign, class, relation and combined conditions, continuing the arithmetic Expression.

Usage​

import lang::cobol85::\syntax::Condition;

Dependencies​

extend lang::cobol85::\syntax::Expression;

Description​

This module extends Expression with the COBOL-85 conditions, below the arithmetic operators in one priority chain: sign conditions (POSITIVE, NEGATIVE, ZERO) and class conditions (NUMERIC, ALPHABETIC, a class name) bind strongest, then the relation conditions in words and in symbols (GREATER THAN, >=, NOT EQUAL TO), then abbreviated relations without a subject, then NOT, AND and OR. Abbreviated combined relation conditions such as A > B AND < C parse with the subject left out, and back ends supply it. Because Rascal priorities do not filter every unwanted reading, the guard nonterminals NotArithmetic and NotEqualSign prevent a sign or class condition from being read as an operand of arithmetic, and < = B from being read as an abbreviated relation. The grammar accepts more condition forms than COBOL allows in some places, which a checker can reject later.

syntax Expression​

syntax Expression
= :minus
> non-assoc ( // sign conditions
positive: Expression 'IS'? 'POSITIVE' NotArithmetic
| notPositive: Expression 'IS'? 'NOT' 'POSITIVE' NotArithmetic
| notPositive: Expression 'NOT' 'IS' 'POSITIVE' NotArithmetic
| negative: Expression 'IS'? 'NEGATIVE' NotArithmetic
| notNegative: Expression 'IS'? 'NOT' 'NEGATIVE' NotArithmetic
| notNegative: Expression 'NOT' 'IS' 'NEGATIVE' NotArithmetic
| zero: Expression 'IS'? ('ZERO' | 'ZEROES' | 'ZEROS') NotArithmetic
| notZero: Expression 'IS'? 'NOT' ('ZERO' | 'ZEROES' | 'ZEROS') NotArithmetic
| notZero: Expression 'NOT' 'IS' ('ZERO' | 'ZEROES' | 'ZEROS') NotArithmetic
// class conditions
| numeric: Expression 'IS'? 'NUMERIC' NotArithmetic
| notNumeric: Expression 'IS'? 'NOT' 'NUMERIC' NotArithmetic
| notNumeric: Expression 'NOT' 'IS' 'NUMERIC' NotArithmetic
| alphabetic: Expression 'IS'? 'ALPHABETIC' NotArithmetic
| notAlphabetic: Expression 'IS'? 'NOT' 'ALPHABETIC' NotArithmetic
| notAlphabetic: Expression 'NOT' 'IS' 'ALPHABETIC' NotArithmetic
| alphabeticLower: Expression 'IS'? 'ALPHABETIC-LOWER' NotArithmetic
| notAlphabeticLower: Expression 'IS'? 'NOT' 'ALPHABETIC-LOWER' NotArithmetic
| notAlphabeticLower: Expression 'NOT' 'IS' 'ALPHABETIC-LOWER' NotArithmetic
| alphabeticUpper: Expression 'IS'? 'ALPHABETIC-UPPER' NotArithmetic
| notAlphabeticUpper: Expression 'IS'? 'NOT' 'ALPHABETIC-UPPER' NotArithmetic
| notAlphabeticUpper: Expression 'NOT' 'IS' 'ALPHABETIC-UPPER' NotArithmetic
| dbcs: Expression 'IS'? 'DBCS' NotArithmetic
| notDbcs: Expression 'IS'? 'NOT' 'DBCS' NotArithmetic
| notDbcs: Expression 'NOT' 'IS' 'DBCS' NotArithmetic
| kanji: Expression 'IS'? 'KANJI' NotArithmetic
| notKanji: Expression 'IS'? 'NOT' 'KANJI' NotArithmetic
| notKanji: Expression 'NOT' 'IS' 'KANJI' NotArithmetic
| inClass: Expression 'IS'? Id NotArithmetic
| notInClass: Expression 'IS'? 'NOT' Id NotArithmetic
| notInClass: Expression 'NOT' 'IS' Id NotArithmetic
)
// GREATER and LESS end at a word boundary: `EQUAL TO ZEROS AND GREATERZERO` has the condition name GREATERZERO
> right ( greaterThan: Expression 'IS'? 'GREATER' !>> [A-Za-z0-9\-] ('THAN' | 'THEN')? Expression
| greaterThan: Expression 'IS'? "\>" NotEqualSign Expression
| notGreaterThan: Expression 'IS'? 'NOT' 'GREATER' !>> [A-Za-z0-9\-] ('THAN' | 'THEN')? Expression
| notGreaterThan: Expression 'IS'? 'NOT' "\>" NotEqualSign Expression
| lessThan: Expression 'IS'? 'LESS' !>> [A-Za-z0-9\-] ('THAN' | 'THEN')? Expression
| lessThan: Expression 'IS'? "\<" NotEqualSign Expression
| notLessThan: Expression 'IS'? 'NOT' 'LESS' !>> [A-Za-z0-9\-] ('THAN' | 'THEN')? Expression
| notLessThan: Expression 'IS'? 'NOT' "\<" NotEqualSign Expression
| equal: Expression 'IS'? 'EQUAL' 'TO'? Expression
| equal: Expression 'IS'? "=" Expression
| notEqual: Expression 'IS'? 'NOT' 'EQUAL' 'TO'? Expression
| notEqual: Expression 'IS'? 'NOT' "=" Expression
| greaterThanOrEqual: Expression 'IS'? 'GREATER' !>> [A-Za-z0-9\-] ('THAN' | 'THEN')? 'OR' 'EQUAL' 'TO'? Expression
| greaterThanOrEqual: Expression 'IS'? "\>=" Expression
| lessThanOrEqual: Expression 'IS'? 'LESS' !>> [A-Za-z0-9\-] ('THAN' | 'THEN')? 'OR' 'EQUAL' 'TO'? Expression
| lessThanOrEqual: Expression 'IS'? "\<" "=" Expression
)
// abbreviated combined relation conditions leave out the subject: `A > B AND < C` means `A > B AND A < C`;
// `AND NOT < C` is the negation of `< C`. Below the full relations, so `A >= B` is not `A > (= B)`
> non-assoc ( greaterThan: 'IS'? 'GREATER' !>> [A-Za-z0-9\-] ('THAN' | 'THEN')? Expression
| greaterThan: 'IS'? "\>" NotEqualSign Expression
| notGreaterThan: 'IS' 'NOT' 'GREATER' !>> [A-Za-z0-9\-] ('THAN' | 'THEN')? Expression
| notGreaterThan: 'IS' 'NOT' "\>" NotEqualSign Expression
| lessThan: 'IS'? 'LESS' !>> [A-Za-z0-9\-] ('THAN' | 'THEN')? Expression
| lessThan: 'IS'? "\<" NotEqualSign Expression
| notLessThan: 'IS' 'NOT' 'LESS' !>> [A-Za-z0-9\-] ('THAN' | 'THEN')? Expression
| notLessThan: 'IS' 'NOT' "\<" NotEqualSign Expression
| equal: 'IS'? 'EQUAL' 'TO'? Expression
| equal: 'IS'? "=" Expression
| notEqual: 'IS' 'NOT' 'EQUAL' 'TO'? Expression
| notEqual: 'IS' 'NOT' "=" Expression
| greaterThanOrEqual: 'IS'? 'GREATER' !>> [A-Za-z0-9\-] ('THAN' | 'THEN')? 'OR' 'EQUAL' 'TO'? Expression
| greaterThanOrEqual: 'IS'? "\>=" Expression
| lessThanOrEqual: 'IS'? 'LESS' !>> [A-Za-z0-9\-] ('THAN' | 'THEN')? 'OR' 'EQUAL' 'TO'? Expression
| lessThanOrEqual: 'IS'? "\<" "=" Expression
)
> negation: 'NOT' Expression
> left conjunction: Expression 'AND' Expression
> left disjunction: Expression 'OR' Expression
;

syntax NotArithmetic​

syntax NotArithmetic = () !>> [*/+\-];

syntax NotEqualSign​

syntax NotEqualSign = () !>> "=";

syntax GreaterThanOrEqualTo​

syntax GreaterThanOrEqualTo
= greaterThan: 'GREATER' 'THAN'? 'OR' 'EQUAL' 'TO'?
| notLessThan: 'NOT' 'LESS' 'THAN'?
| greaterThanOrEqual: "\>="
| notLessThanSign: 'NOT' "\<"
;

syntax GreaterThan​

syntax GreaterThan
= greaterThanSign: "\>"
| greaterThan: 'GREATER' 'THAN'?
;

syntax CobwordKeywords​

keyword CobwordKeywords
= 'ALPHABETIC'
| 'ALPHABETIC-LOWER'
| 'ALPHABETIC-UPPER'
| 'AND'
| 'DBCS'
| 'EQUAL'
| 'GREATER'
| 'IS'
| 'KANJI'
| 'LESS'
| 'NEGATIVE'
| 'NOT'
| 'NUMERIC'
| 'OR'
| 'POSITIVE'
| 'THAN'
| 'THEN'
| 'TO'
| 'ZERO'
| 'ZEROES'
| 'ZEROS'
;