Class: Loxxy::Ast::LoxIfStmt

Inherits:
LoxCompoundExpr show all
Defined in:
lib/loxxy/ast/lox_if_stmt.rb

Instance Attribute Summary collapse

Attributes inherited from LoxCompoundExpr

#subnodes

Attributes inherited from LoxNode

#position

Instance Method Summary collapse

Methods inherited from LoxNode

#done!

Constructor Details

#initialize(aPosition, condExpr, thenStmt, elseStmt) ⇒ LoxIfStmt

Returns a new instance of LoxIfStmt.

Parameters:



18
19
20
21
22
# File 'lib/loxxy/ast/lox_if_stmt.rb', line 18

def initialize(aPosition, condExpr, thenStmt, elseStmt)
  super(aPosition, [condExpr])
  @then_stmt = thenStmt
  @else_stmt = elseStmt
end

Instance Attribute Details

#else_stmtLoxNode, NilClass (readonly)

Returns code of else branch.

Returns:

  • (LoxNode, NilClass)

    code of else branch



12
13
14
# File 'lib/loxxy/ast/lox_if_stmt.rb', line 12

def else_stmt
  @else_stmt
end

#then_stmtLoxNode (readonly)

Returns code of then branch.

Returns:

  • (LoxNode)

    code of then branch



9
10
11
# File 'lib/loxxy/ast/lox_if_stmt.rb', line 9

def then_stmt
  @then_stmt
end

Instance Method Details

#accept(visitor) ⇒ Object

Part of the 'visitee' role in Visitor design pattern.

Parameters:



26
27
28
# File 'lib/loxxy/ast/lox_if_stmt.rb', line 26

def accept(visitor)
  visitor.visit_if_stmt(self)
end

#conditionLoxNode

Accessor to the condition expression

Returns:



32
33
34
# File 'lib/loxxy/ast/lox_if_stmt.rb', line 32

def condition
  subnodes[0]
end