A toy dynamic programming language written in Ruby
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

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