Class: Token

Inherits:
Object
  • Object
show all
Defined in:
lib/lexer.rb

Overview

require ‘benchmark’

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tab) ⇒ Token

Returns a new instance of Token.



7
8
9
# File 'lib/lexer.rb', line 7

def initialize tab
  @kind,@val,@pos=*tab
end

Instance Attribute Details

#kindObject

Returns the value of attribute kind.



6
7
8
# File 'lib/lexer.rb', line 6

def kind
  @kind
end

#posObject

Returns the value of attribute pos.



6
7
8
# File 'lib/lexer.rb', line 6

def pos
  @pos
end

#valObject

Returns the value of attribute val.



6
7
8
# File 'lib/lexer.rb', line 6

def val
  @val
end

Instance Method Details

#is_a?(kind) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/lexer.rb', line 11

def is_a? kind
  case kind
  when Symbol
    return @kind==kind
  when Array
    for sym in kind
      return true if @kind==sym
    end
    return false
  else
    raise "wrong type during lookahead"
  end
end