A toy dynamic programming language written in Ruby
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

conditional.rb 459B

123456789101112131415161718192021222324
  1. class AST::Conditional
  2. attr_reader :branches
  3. def initialize(branches)
  4. @branches = branches
  5. end
  6. def ==(other)
  7. other.is_a?(AST::Conditional) && other.branches == @branches
  8. end
  9. def execute(env)
  10. @branches.each do |branch|
  11. if branch.condition.execute(env)
  12. value = nil
  13. branch.block.statements.each do |statement|
  14. value = statement.execute(env)
  15. end
  16. return value
  17. end
  18. end
  19. end
  20. end