Class: Yadriggy::Number
- Defined in:
- lib/yadriggy/ast.rb,
lib/yadriggy/ast_value.rb
Overview
Numeric literal.
Instance Attribute Summary collapse
-
#column ⇒ Integer
readonly
The column.
-
#line_no ⇒ Integer
readonly
The line number.
-
#value ⇒ Numeric
readonly
The number.
Attributes inherited from ASTnode
Class Method Summary collapse
Instance Method Summary collapse
-
#accept(evaluator) ⇒ void
A method for Visitor pattern.
-
#const_value ⇒ Object
This is defined by attr_reader.
-
#initialize(sexp) ⇒ Number
constructor
A new instance of Number.
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
Returns a new instance of Number.
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# 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 when :@rational sexp[1].to_r when :@imaginary Complex(sexp[1]) else raise "unknown symbol #{sexp[0]}" end @line_no = sexp[2][0].to_i @column = sexp[2][1].to_i end |
Instance Attribute Details
#column ⇒ Integer (readonly)
Returns the column.
257 258 259 |
# File 'lib/yadriggy/ast.rb', line 257 def column @column end |
#line_no ⇒ Integer (readonly)
Returns the line number.
255 256 257 |
# File 'lib/yadriggy/ast.rb', line 255 def line_no @line_no end |
#value ⇒ Numeric (readonly)
Returns the number.
253 254 255 |
# File 'lib/yadriggy/ast.rb', line 253 def value @value end |
Class Method Details
.tags ⇒ Object
259 260 261 |
# File 'lib/yadriggy/ast.rb', line 259 def self.() [:@int, :@float, :@rational, :@imaginary] end |
Instance Method Details
#accept(evaluator) ⇒ void
This method returns an undefined value.
A method for Visitor pattern.
287 288 289 |
# File 'lib/yadriggy/ast.rb', line 287 def accept(evaluator) evaluator.number(self) end |
#const_value ⇒ Object
This is defined by attr_reader. def value() @value end
267 |
# File 'lib/yadriggy/ast_value.rb', line 267 def const_value() value end |