Class: Rley::Lexical::Literal

Inherits:
Token
  • Object
show all
Defined in:
lib/rley/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. 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

#lexeme, #position, #terminal

Instance Method Summary collapse

Constructor Details

#initialize(aValue, theLexeme, aTerminal, aPosition = nil) ⇒ Literal

Constructor.

Parameters:

  • aValue (Object)

    value of the token in internal representation

  • theLexeme (String)

    the lexeme (= piece of text from input)

  • aTerminal (Syntax::Terminal, String)
  • aPosition (Rley::Lexical::Position) (defaults to: nil)

    line, column position pf token



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

def initialize(aValue, theLexeme, aTerminal, aPosition = nil)
  super(theLexeme, aTerminal, aPosition)
  @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/rley/lexical/literal.rb', line 15

def value
  @value
end