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.
25 lines
636 B
25 lines
636 B
module Lox
|
|
module Expr
|
|
def self.expr(name, *children)
|
|
klass = Struct.new(name.to_s, *children) do
|
|
def accept(visitor)
|
|
klass = self.class.to_s.split("::").last.downcase
|
|
visitor.send("visit_#{klass}", self)
|
|
end
|
|
end
|
|
const_set(name, klass)
|
|
end
|
|
|
|
expr :Assign, :name, :value
|
|
expr :Binary, :left, :op, :right
|
|
expr :Call, :callee, :paren, :args
|
|
expr :Get, :object, :name
|
|
expr :Grouping, :expr
|
|
expr :Literal, :value
|
|
expr :Logical, :left, :op, :right
|
|
expr :Set, :object, :name, :value
|
|
expr :Unary, :op, :right
|
|
expr :Variable, :name
|
|
end
|
|
end
|