Class: Dendroid::Lexical::Literal

Inherits:
Token
  • Object
show all
Defined in:
lib/dendroid/lexical/literal.rb

Overview

A literal (value) is a token that represents a data value in the parsed language. For instance, in Ruby data values such as strings, numbers, regular expression,… can appear directly in the source code as text. These are examples of literal values. One responsibility of a tokenizer/lexer is to convert the text representation into a corresponding value in a convenient format for the interpreter/compiler.

Instance Attribute Summary collapse

Attributes inherited from Token

#position, #source, #terminal

Instance Method Summary collapse

Methods inherited from Token

#pos_to_s

Constructor Details

#initialize(original, pos, symbol, aValue) ⇒ Literal

Constructor.

Parameters:



22
23
24
25
# File 'lib/dendroid/lexical/literal.rb', line 22

def initialize(original, pos, symbol, aValue)
  super(original, pos, symbol)
  @value = aValue
end

Instance Attribute Details

#valueObject (readonly)

Returns The value expressed in one of the target datatype.

Returns:

  • (Object)

    The value expressed in one of the target datatype.



15
16
17
# File 'lib/dendroid/lexical/literal.rb', line 15

def value
  @value
end

Instance Method Details

#literal?Boolean

Returns true if the token is a literal (has a value associated with is).

Returns:

  • (Boolean)

    true if the token is a literal (has a value associated with is)



28
29
30
# File 'lib/dendroid/lexical/literal.rb', line 28

def literal?
  true
end