Skip to content

Instantly share code, notes, and snippets.

Created June 27, 2017 23:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/8eafb1862f4acec2b0a1824a31504f35 to your computer and use it in GitHub Desktop.
Save anonymous/8eafb1862f4acec2b0a1824a31504f35 to your computer and use it in GitHub Desktop.
# the base
abstract class Stmt
abstract def accept(visitor : Interpreter)
end
# the class with the constructor
class BlockStmt < Stmt
property statements
def initialize(statements : Array(Stmt | Nil))
@statements = statements
end
def accept(visitor : Interpreter)
visitor.visit_block_stmt(self)
end
end
# the class in the array
class ExprStmt < Stmt
property expression
def initialize(expression : Expr)
@expression = expression
end
def accept(visitor : Interpreter)
visitor.visit_expr_stmt(self)
end
end
# this creates the exception
block = BlockStmt.new([body, ExprStmt.new(increment)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment