A toy dynamic programming language written in Ruby
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

unary.rb 392B

123456789101112131415161718192021
  1. class AST::Unary
  2. attr_reader :operation, :expr
  3. def initialize(operation, expr)
  4. @operation = operation
  5. @expr = expr
  6. end
  7. def ==(other)
  8. other.operation == @operation && other.expr == @expr
  9. end
  10. def execute(env)
  11. case @operation
  12. when AST::Operators::SUBTRACT
  13. 0.0 - @expr.execute(env)
  14. when AST::Operators::NOT
  15. !@expr.execute(env)
  16. end
  17. end
  18. end