Class: Yadriggy::Number

Inherits:
ASTnode show all
Defined in:
lib/yadriggy/ast.rb,
lib/yadriggy/ast_value.rb

Overview

Numeric literal.

Instance Attribute Summary collapse

Attributes inherited from ASTnode

#parent, #usertype

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ASTnode

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

Constructor Details

#initialize(sexp) ⇒ Number



263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/yadriggy/ast.rb', line 263

def initialize(sexp)
  @value = case sexp[0]
           when :@int
             if sexp[1].start_with? "0x"
               sexp[1].hex
             else
               sexp[1].to_i
             end
           when :@float
             sexp[1].to_f
           else
             raise "unknown symbol " + sexp[0]
           end
  @line_no = sexp[2][0].to_i
  @column = sexp[2][1].to_i
end

Instance Attribute Details

#columnInteger (readonly)



257
258
259
# File 'lib/yadriggy/ast.rb', line 257

def column
  @column
end

#line_noInteger (readonly)



255
256
257
# File 'lib/yadriggy/ast.rb', line 255

def line_no
  @line_no
end

#valueNumeric (readonly)



253
254
255
# File 'lib/yadriggy/ast.rb', line 253

def value
  @value
end

Class Method Details

.tagsObject



259
260
261
# File 'lib/yadriggy/ast.rb', line 259

def self.tags()
  [:@int, :@float]
end

Instance Method Details

#accept(evaluator) ⇒ void

This method returns an undefined value.

A method for Visitor pattern.



283
284
285
# File 'lib/yadriggy/ast.rb', line 283

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

#const_valueObject

This is defined by attr_reader. def value() @value end



267
# File 'lib/yadriggy/ast_value.rb', line 267

def const_value() value end