Created
June 27, 2017 23:46
-
-
Save anonymous/8eafb1862f4acec2b0a1824a31504f35 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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