Class: Loxxy::Ast::LoxVarStmt

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

Overview

This AST node represents a variable declaration

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, aName, aValue) ⇒ LoxVarStmt

Returns a new instance of LoxVarStmt.

Parameters:

  • aPosition (Rley::Lexical::Position)

    Position of the entry in the input stream.

  • aName (String)

    name of the variable

  • aValue (Loxxy::Ast::LoxNode, NilClass)

    initial value for the variable



15
16
17
18
19
# File 'lib/loxxy/ast/lox_var_stmt.rb', line 15

def initialize(aPosition, aName, aValue)
  initial_value = aValue || Datatype::Nil.instance
  super(aPosition, [initial_value])
  @name = aName
end

Instance Attribute Details

#nameString (readonly)

Returns variable name.

Returns:

  • (String)

    variable name



10
11
12
# File 'lib/loxxy/ast/lox_var_stmt.rb', line 10

def name
  @name
end

Instance Method Details

#accept(visitor) ⇒ Object

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

Parameters:



23
24
25
# File 'lib/loxxy/ast/lox_var_stmt.rb', line 23

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