def add_next_infix_terms(priority, first)
      old_operator = nil
      term = first
      loop do
        # we expect an infix operator
        operator = get_operator
        logger.debug "we found operator '#{operator}'" unless operator.nil?
        if operator.nil? || operator.prefix? || operator.priority <= priority
          logger.debug "operator '#{operator}' is nil" if operator.nil?
          logger.debug "operator '#{operator}' is prefex" if !operator.nil? && operator.prefix?
          if !operator.nil? && operator.priority <= priority
            logger.debug "operator '#{operator}' has less priority #{operator.priority}" \
                         " than #{priority}"
          end
          logger.debug "get_next_infix_terms: #{term}"
          return term
        end
        if old_operator.nil? || old_operator.priority >= operator.priority
          # old operator has not less priority
          read_token
          new_term = read_maximal_term(operator.priority)
          error("to few arguments for operator '#{operator}'") if new_term.nil?
          logger.debug "is '#{old_operator}' == '#{operator}' : #{old_operator == operator}"
          if old_operator == operator
            if operator.maximum && term.args.size + 1 >= operator.maximum
              raise "to much arguments for operator '#{operator}'"
            end
            term.add(new_term)
          else
            also_new_term = Term.new(operator)
            also_new_term.add(term)
            also_new_term.add(new_term)
            term = also_new_term
          end
        else
          # old operator has less priority
          new_term = read_maximal_term(operator.priority)
          error("to few arguments for operator '#{operator}'") if new_term.nil?
          also_new_term = Term.new(operator)
          also_new_term.add(term)
          also_new_term.add(new_term)
          term = also_new_term
        end
        old_operator = operator
      end
    end
def add_next_infix_terms(priority, first)
      old_operator = nil
      term = first
      loop do
        # we expect an infix operator
        operator = get_operator
        logger.debug "we found operator '#{operator}'" unless operator.nil?
        if operator.nil? || operator.prefix? || operator.priority <= priority
          logger.debug "operator '#{operator}' is nil" if operator.nil?
          logger.debug "operator '#{operator}' is prefex" if !operator.nil? && operator.prefix?
          if !operator.nil? && operator.priority <= priority
            logger.debug "operator '#{operator}' has less priority #{operator.priority}" \
                         " than #{priority}"
          end
          logger.debug "get_next_infix_terms: #{term}"
          return term
        end
        if old_operator.nil? || old_operator.priority >= operator.priority
          # old operator has not less priority
          read_token
          new_term = read_maximal_term(operator.priority)
          error("to few arguments for operator '#{operator}'") if new_term.nil?
          logger.debug "is '#{old_operator}' == '#{operator}' : #{old_operator == operator}"
          if old_operator == operator
            if operator.maximum && term.args.size + 1 >= operator.maximum
              raise "to much arguments for operator '#{operator}'"
            end
            term.add(new_term)
          else
            also_new_term = Term.new(operator)
            also_new_term.add(term)
            also_new_term.add(new_term)
            term = also_new_term
          end
        else
          # old operator has less priority
          new_term = read_maximal_term(operator.priority)
          error("to few arguments for operator '#{operator}'") if new_term.nil?
          also_new_term = Term.new(operator)
          also_new_term.add(term)
          also_new_term.add(new_term)
          term = also_new_term
        end
        old_operator = operator
      end
    end
rubocop:enable Metrics/PerceivedComplexity,Metrics/AbcSize,Metrics/CyclomaticComplexity
 rubocop:enable Metrics/MethodLength
 rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/BlockLength
 rubocop:disable Metrics/MethodLength,Metrics/PerceivedComplexity