Class: Yadriggy::Exprs

Inherits:
ASTnode show all
Includes:
AstHelper
Defined in:
lib/yadriggy/ast.rb

Overview

expressions, or progn in Lisp.

Instance Attribute Summary collapse

Attributes inherited from ASTnode

#parent, #usertype

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AstHelper

#has_tag?, #to_node, #to_nodes

Methods inherited from ASTnode

#add_child, #add_children, #const_value, #const_value_in_class, #get_context_class, #get_receiver_object, #is_proc?, #pretty_print, #root, #source_location, #source_location_string, #value, #value_in_class

Constructor Details

#initialize(sexp) ⇒ Exprs

Returns a new instance of Exprs.



389
390
391
392
# File 'lib/yadriggy/ast.rb', line 389

def initialize(sexp)
  @expressions = to_nodes(sexp)
  add_children(@expressions)
end

Instance Attribute Details

#expressionsArray<ASTnode> (readonly)

Returns the expressions. It may be an empty array.

Returns:

  • (Array<ASTnode>)

    the expressions. It may be an empty array.



373
374
375
# File 'lib/yadriggy/ast.rb', line 373

def expressions
  @expressions
end

Class Method Details

.make(sexp) ⇒ Exprs|ASTnode

Returns an AST.

Parameters:

  • sexp (Array)

    an S-expression.

Returns:



377
378
379
380
381
382
383
384
385
386
387
# File 'lib/yadriggy/ast.rb', line 377

def self.make(sexp)
  if sexp.length == 1
    if sexp[0][0] == :void_stmt
      Exprs.new([])
    else
      ASTree.to_node(sexp[0])
    end
  else
    Exprs.new(sexp)
  end
end

Instance Method Details

#accept(evaluator) ⇒ void

This method returns an undefined value.

A method for Visitor pattern.

Parameters:

  • evaluator (Eval)

    the visitor of Visitor pattern.



397
398
399
# File 'lib/yadriggy/ast.rb', line 397

def accept(evaluator)
  evaluator.exprs(self)
end