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 LoxCompoundExpr

#accept

Methods inherited from LoxNode

#accept, #done!

Methods included from ASTVisitee

#define_accept, #snake_case

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