Class: Lrama::Context

Inherits:
Object
  • Object
show all
Includes:
Report::Duration
Defined in:
lib/lrama/context.rb

Overview

This is passed to a template

Constant Summary collapse

ErrorActionNumber =
-Float::INFINITY
BaseMin =
-Float::INFINITY

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Report::Duration

enable, enabled?, #report_duration

Constructor Details

#initialize(states) ⇒ Context



16
17
18
19
20
21
22
23
24
# File 'lib/lrama/context.rb', line 16

def initialize(states)
  @states = states
  @yydefact = nil
  @yydefgoto = nil
  # Array of array
  @_actions = []

  compute_tables
end

Instance Attribute Details

#statesObject (readonly)

TODO: It might be better to pass ‘states` to Output directly?



14
15
16
# File 'lib/lrama/context.rb', line 14

def states
  @states
end

#yydefactObject (readonly)

TODO: It might be better to pass ‘states` to Output directly?



14
15
16
# File 'lib/lrama/context.rb', line 14

def yydefact
  @yydefact
end

#yydefgotoObject (readonly)

TODO: It might be better to pass ‘states` to Output directly?



14
15
16
# File 'lib/lrama/context.rb', line 14

def yydefgoto
  @yydefgoto
end

#yylastObject (readonly)

TODO: It might be better to pass ‘states` to Output directly?



14
15
16
# File 'lib/lrama/context.rb', line 14

def yylast
  @yylast
end

#yypact_ninfObject (readonly)

TODO: It might be better to pass ‘states` to Output directly?



14
15
16
# File 'lib/lrama/context.rb', line 14

def yypact_ninf
  @yypact_ninf
end

#yytable_ninfObject (readonly)

TODO: It might be better to pass ‘states` to Output directly?



14
15
16
# File 'lib/lrama/context.rb', line 14

def yytable_ninf
  @yytable_ninf
end

Instance Method Details

#yycheckObject



132
133
134
# File 'lib/lrama/context.rb', line 132

def yycheck
  @check
end

#yyfinalObject

State number of final (accepted) state



43
44
45
46
47
48
49
# File 'lib/lrama/context.rb', line 43

def yyfinal
  @states.states.find do |state|
    state.items.find do |item|
      item.lhs.accept_symbol? && item.end_of_rule?
    end
  end.id
end

#yymaxutokObject

Last token number



72
73
74
# File 'lib/lrama/context.rb', line 72

def yymaxutok
  @states.terms.map(&:token_id).max
end

#yynntsObject

Number of nterms



57
58
59
# File 'lib/lrama/context.rb', line 57

def yynnts
  @states.nterms.count
end

#yynrulesObject

Number of rules



62
63
64
# File 'lib/lrama/context.rb', line 62

def yynrules
  @states.rules.count
end

#yynstatesObject

Number of states



67
68
69
# File 'lib/lrama/context.rb', line 67

def yynstates
  @states.states.count
end

#yyntokensObject

Number of terms



52
53
54
# File 'lib/lrama/context.rb', line 52

def yyntokens
  @states.terms.count
end

#yypactObject



120
121
122
# File 'lib/lrama/context.rb', line 120

def yypact
  @base[0...yynstates]
end

#yypgotoObject



124
125
126
# File 'lib/lrama/context.rb', line 124

def yypgoto
  @base[yynstates..-1]
end

#yyr1Object

Mapping from rule number to symbol number of LHS. Dummy rule is appended as the first element whose value is 0 because 0 means error in yydefact.



145
146
147
148
149
150
151
152
153
# File 'lib/lrama/context.rb', line 145

def yyr1
  a = [0]

  @states.rules.each do |rule|
    a << rule.lhs.number
  end

  return a
end

#yyr2Object

Mapping from rule number to length of RHS. Dummy rule is appended as the first element whose value is 0 because 0 means error in yydefact.



158
159
160
161
162
163
164
165
166
# File 'lib/lrama/context.rb', line 158

def yyr2
  a = [0]

  @states.rules.each do |rule|
    a << rule.rhs.count
  end

  return a
end

#yyrlineObject

Mapping from rule number to line number of the rule is defined. Dummy rule is appended as the first element whose value is 0 because 0 means error in yydefact.



103
104
105
106
107
108
109
110
111
# File 'lib/lrama/context.rb', line 103

def yyrline
  a = [0]

  @states.rules.each do |rule|
    a << rule.lineno
  end

  return a
end

#yystosObject



136
137
138
139
140
# File 'lib/lrama/context.rb', line 136

def yystos
  @states.states.map do |state|
    state.accessing_symbol.number
  end
end

#yysymbol_kind_tObject

enum yysymbol_kind_t



36
37
38
39
40
# File 'lib/lrama/context.rb', line 36

def yysymbol_kind_t
  @states.symbols.map do |sym|
    [sym.enum_name, sym.number, sym.comment]
  end.unshift(["YYSYMBOL_YYEMPTY", -2, nil])
end

#yytableObject



128
129
130
# File 'lib/lrama/context.rb', line 128

def yytable
  @table
end

#yytnameObject

Mapping from symbol number to its name



114
115
116
117
118
# File 'lib/lrama/context.rb', line 114

def yytname
  @states.symbols.sort_by(&:number).map do |sym|
    sym.display_name
  end
end

#yytokentypeObject

enum yytokentype



27
28
29
30
31
32
33
# File 'lib/lrama/context.rb', line 27

def yytokentype
  @states.terms.reject do |term|
    0 < term.token_id && term.token_id < 128
  end.map do |term|
    [term.id.s_value, term.token_id, term.display_name]
  end.unshift(["YYEMPTY", -2, nil])
end

#yytranslateObject

YYTRANSLATE

yytranslate is a mapping from token id to symbol number



79
80
81
82
83
84
85
86
87
88
# File 'lib/lrama/context.rb', line 79

def yytranslate
  # 2 is YYSYMBOL_YYUNDEF
  a = Array.new(yymaxutok, 2)

  @states.terms.each do |term|
    a[term.token_id] = term.number
  end

  return a
end

#yytranslate_invertedObject



90
91
92
93
94
95
96
97
98
# File 'lib/lrama/context.rb', line 90

def yytranslate_inverted
  a = Array.new(@states.symbols.count, @states.undef_symbol.token_id)

  @states.terms.each do |term|
    a[term.number] = term.token_id
  end

  return a
end