A toy dynamic programming language written in Ruby
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

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