Sha256: 8e324589d7a038a62e3aa1e0cc7c9b518aef0741bd6211e26828f0b48991f748

Contents?: true

Size: 787 Bytes

Versions: 1

Compression:

Stored size: 787 Bytes

Contents

require 'gobstones/lang/expressions/two_arg_expression'
require 'gobstones/runner/errors/gobstones_runtime_error'

module Gobstones

  module Lang

    class Add < TwoArgExpression

      evaluates_with :+

    end

    class Sub < TwoArgExpression

      evaluates_with :-

    end

    class Mul < TwoArgExpression

      evaluates_with :*

    end

    class Div < TwoArgExpression

      def evaluate(context=nil)
        begin
          left_expr.evaluate(context) / right_expr.evaluate(context)
        rescue ZeroDivisionError
          raise Gobstones::Runner::GobstonesRuntimeError, 'zero division'
        end
      end

    end

    class Mod < TwoArgExpression

      evaluates_with :%

    end

    class Pow < TwoArgExpression

      evaluates_with :**

    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gobstones-0.0.1.1 lib/gobstones/lang/expressions/arithmetic_expressions.rb