Class BinaryExpressions

java.lang.Object
org.ek9lang.compiler.phase1.BinaryExpressions

final class BinaryExpressions extends Object
THE reading of a binary or prefix expression alternative for the phase-1 operand-parentheses checks - E08269 (CoalescingOperandParenthesesOrError), E08273 (NotOperandParenthesesOrError) and E08274 (DoubleNegationOrError). Use it for any further rule over an operator's operand rather than another private copy.

A binary expression is any alternative with both a left and a right operand. A prefix expression is one of the symbol/word prefix alternatives of EK9.g4 (PREFIX_OPERATORS) with no left. Word not is a prefix too, but it is the loose negation and is read on its own (isWordNot(EK9Parser.ExpressionContext)). A parenthesised operand is a primary, so it is never a binary or prefix expression here.

  • Field Details

    • PREFIX_OPERATORS

      static final Set<Integer> PREFIX_OPERATORS
      The prefix operators of expression other than word not, exactly as EK9.g4 lists them: $$ (TOJSON), $ (DOLLAR), #^ (PROMOTE), length [of], #< (PREFIX), #> (SUFFIX), #? (HASHCODE), abs [of], sqrt [of], ~ (TILDE) and unary - (SUB with no left operand). Pinned against the grammar by BinaryExpressionsTest.
  • Method Details

    • isPrefix

      static boolean isPrefix(EK9Parser.ExpressionContext ctx)
      A prefix expression (not word not): the operator comes first and there is one operand, prefixOperandOf(EK9Parser.ExpressionContext).
    • prefixOperandOf

      The single operand of a prefix expression (or of word not).
    • isWordNot

      static boolean isWordNot(EK9Parser.ExpressionContext ctx)
      Word not applied to an operand: not b. Not the not inside is not empty, not matches, not contains or not in, which is a neg label on another operator.
    • isNegation

      static boolean isNegation(EK9Parser.ExpressionContext ctx)
      A negation applied to one operand: word not b, ~b or unary -x. Keyed on the OPERATOR, not the spelling (Steve, 2026-10-08, Q9): all three call _negate (OperatorMap.getPrefixForward(String), the mapping IR generation lowers them through), so any two of them applied to one operand cancel out (E08274, DoubleNegationOrError). Binary - has a left operand and is subtraction, never a negation, and -- is the decrement token, never two negations.
    • isSignedLiteral

      static boolean isSignedLiteral(EK9Parser.ExpressionContext ctx)
      A literal with its sign folded in (-5, -2.5, -10#GBP): not a negation - it calls nothing - but SPELT with one, so E08274 counts it when a negation is applied to it (- -5 is 5).
    • negatedOperandOf

      static EK9Parser.ExpressionContext negatedOperandOf(EK9Parser.ExpressionContext negation)
      What a negation is applied to, looking through parentheses (Q8): in not (not b) and -(-x) the operand of the outer negation is the inner one. Parentheses group; they do not change what is negated.
    • negationApplyingTo

      The negation that ctx is the operand of, looking through parentheses (ctx is not b in ~((not b))); null when it is not the operand of a negation.
    • withoutParentheses

      The expression inside any number of enclosing parentheses: b for ((b)).
    • isBinary

      static boolean isBinary(EK9Parser.ExpressionContext ctx)
    • operatorOf

      static org.antlr.v4.runtime.Token operatorOf(EK9Parser.ExpressionContext ctx)
      The operator token of a binary expression. The 'in' alternative has no 'op' label.
    • sourceText

      static String sourceText(org.antlr.v4.runtime.ParserRuleContext ctx)
      The source as written (getText() would drop the spaces).