Modernization Hub

Infix Notation

Enhanced Definition

Infix notation is a common method for writing expressions where operators are placed *between* their operands. This human-readable format is widely used in programming languages on the mainframe, particularly for arithmetic, logical, and relational operations, making expressions intuitive to understand and parse.

Key Characteristics

    • Operator Placement: The operator (e.g., +, -, *, /, =, AND, OR, >) is positioned directly between the two operands it acts upon.
    • Readability: It closely mimics standard mathematical notation, enhancing code readability and reducing the learning curve for developers working with mainframe languages.
    • Precedence and Associativity: Requires specific rules for operator precedence (e.g., multiplication before addition) and associativity (e.g., left-to-right for subtraction) to unambiguously evaluate expressions.
    • Parentheses for Override: Parentheses () are used to explicitly group operations, allowing developers to override default precedence rules and force a specific order of evaluation.
    • Common in High-Level Languages: Predominant in high-level mainframe languages like COBOL, PL/I, REXX, and SQL for expressing computations and conditional logic.

Use Cases

    • COBOL Arithmetic Computations: Performing calculations within COMPUTE statements, such as COMPUTE TOTAL-AMOUNT = QUANTITY * UNIT-PRICE + TAX-AMOUNT..
    • REXX Expression Evaluation: Assigning the result of an arithmetic or string concatenation expression to a variable, e.g., result = (value1 + value2) * factor.
    • SQL WHERE Clauses: Specifying conditions for data retrieval or manipulation in DB2 or IMS DB/DC (via SQL), like SELECT CUST_NAME FROM CUSTOMERS WHERE BALANCE > 1000 AND STATUS = 'ACTIVE'.
    • PL/I Conditional Logic: Constructing complex expressions for data transformation or conditional branching, such as IF A > B AND C = D THEN CALL PROCESS_DATA;.

Related Concepts

Infix notation is fundamental to how expressions are written and processed in most high-level mainframe programming languages. It contrasts with prefix notation (operators before operands, sometimes seen in specialized contexts or internal compiler representations) and postfix notation (operators after operands, often used in stack-based computations or Reverse Polish Notation). Understanding infix notation is crucial for correctly interpreting and writing code that involves arithmetic, logical, or relational operations, directly impacting program logic and data manipulation within z/OS applications.

Best Practices:
  • Use Parentheses Liberally: Even when default precedence rules would yield the correct result, use parentheses () to explicitly clarify the order of operations, significantly improving code readability and maintainability.
  • Understand Operator Precedence: Be thoroughly familiar with the specific operator precedence rules of the language (COBOL, REXX, SQL) being used to avoid unexpected evaluation outcomes.
  • Avoid Ambiguity: Structure complex expressions to be clear and unambiguous. Break down very long expressions into smaller, more manageable statements if readability suffers.
  • Test Expressions Thoroughly: Always test expressions involving infix operators with various data inputs to ensure they produce the expected results, especially when dealing with mixed data types or potential division by zero scenarios.
  • Consistency: Maintain consistent formatting and spacing around operators to enhance visual clarity and make expressions easier to parse mentally.

Related Vendors

Trax Softworks

3 products

Related Categories