Class: Rucc::TokenGen

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(files) ⇒ TokenGen

Returns a new instance of TokenGen.

Parameters:



6
7
8
9
# File 'lib/rucc/token_gen.rb', line 6

def initialize(files)
  @files = files
  @pos = nil
end

Instance Attribute Details

#posObject

Returns the value of attribute pos.



10
11
12
# File 'lib/rucc/token_gen.rb', line 10

def pos
  @pos
end

Instance Method Details

#make_char(c, enc) ⇒ Token

Parameters:

  • c (Integer)
  • enc (ENC)

Returns:



45
46
47
# File 'lib/rucc/token_gen.rb', line 45

def make_char(c, enc)
  make_token(T::CHAR, c: c, enc: enc)
end

#make_ident(p) ⇒ Token

Parameters:

  • p (String)

Returns:



38
39
40
# File 'lib/rucc/token_gen.rb', line 38

def make_ident(p)
  make_token(T::IDENT, sval: p)
end

#make_invalid(c) ⇒ Token

Parameters:

  • c (Integer)

Returns:



64
65
66
# File 'lib/rucc/token_gen.rb', line 64

def make_invalid(c)
  make_token(T::INVALID, c: c)
end

#make_keyword(id) ⇒ Token

Parameters:

  • id (Char)

Returns:



58
59
60
# File 'lib/rucc/token_gen.rb', line 58

def make_keyword(id)
  make_token(T::KEYWORD, id: id)
end

#make_number(s) ⇒ Token

Parameters:

  • s (String)

Returns:



32
33
34
# File 'lib/rucc/token_gen.rb', line 32

def make_number(s)
  make_token(T::NUMBER, sval: s)
end

#make_strtok(s, enc) ⇒ Token

Parameters:

  • s (String)
  • enc (ENC)

Returns:



52
53
54
# File 'lib/rucc/token_gen.rb', line 52

def make_strtok(s, enc)
  make_token(T::STRING, sval: s, enc: enc)
end

#make_token(kind, value = {}) ⇒ Token

Parameters:

  • kind (T)
  • value (Hash) (defaults to: {})

Returns:



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rucc/token_gen.rb', line 16

def make_token(kind, value = {})
  f = @files.current
  Util.assert!{ !pos.nil? }
  params = {
    file: f,
    count: f.ntok,
    hideset: Set.new,
    line: pos.line,
    column: pos.column,
  }
  f.incr_ntok!
  Token.new(kind, value.merge(params))
end