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.

variable_declaration.rb 445B

123456789101112131415161718192021
  1. class AST::VariableDeclaration
  2. attr_reader :name, :value
  3. def initialize(name, value)
  4. @name = name
  5. @value = value
  6. end
  7. def ==(other)
  8. other.is_a?(AST::VariableDeclaration) && other.name == @name &&
  9. other.value == @value
  10. end
  11. def execute(env)
  12. if env.data[@name.name].nil?
  13. env.set(@name.name, @value)
  14. else
  15. raise "Invalid declaration of previously declared variable #{@name.name}"
  16. end
  17. end
  18. end