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

Returns a new instance of Context.



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

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?



12
13
14
# File 'lib/lrama/context.rb', line 12

def states
  @states
end

Instance Method Details

#yycheckObject



140
141
142
# File 'lib/lrama/context.rb', line 140

def yycheck
  @check
end

#yydefactObject



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

def yydefact
  @yydefact
end

#yydefgotoObject



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

def yydefgoto
  @yydefgoto
end

#yyfinalObject

State number of final (accepted) state



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

def yyfinal
  @states.states.find do |state|
    state.items.find do |item|
      item.rule.lhs.id.s_value == "$accept" && item.end_of_rule?
    end
  end.id
end

#yylastObject



49
50
51
# File 'lib/lrama/context.rb', line 49

def yylast
  @yylast
end

#yymaxutokObject

Last token number



74
75
76
# File 'lib/lrama/context.rb', line 74

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

#yynntsObject

Number of nterms



59
60
61
# File 'lib/lrama/context.rb', line 59

def yynnts
  @states.nterms.count
end

#yynrulesObject

Number of rules



64
65
66
# File 'lib/lrama/context.rb', line 64

def yynrules
  @states.rules.count
end

#yynstatesObject

Number of states



69
70
71
# File 'lib/lrama/context.rb', line 69

def yynstates
  @states.states.count
end

#yyntokensObject

Number of terms



54
55
56
# File 'lib/lrama/context.rb', line 54

def yyntokens
  @states.terms.count
end

#yypactObject



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

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

#yypact_ninfObject



112
113
114
# File 'lib/lrama/context.rb', line 112

def yypact_ninf
  @yypact_ninf
end

#yypgotoObject



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

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.



153
154
155
156
157
158
159
160
161
# File 'lib/lrama/context.rb', line 153

def yyr1
  a = [0]

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

  return a
end

#yyr2Object

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



166
167
168
169
170
171
172
173
174
# File 'lib/lrama/context.rb', line 166

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.



95
96
97
98
99
100
101
102
103
# File 'lib/lrama/context.rb', line 95

def yyrline
  a = [0]

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

  return a
end

#yystosObject



144
145
146
147
148
# File 'lib/lrama/context.rb', line 144

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

#yysymbol_kind_tObject

enum yysymbol_kind_t



34
35
36
37
38
# File 'lib/lrama/context.rb', line 34

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

#yytableObject



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

def yytable
  @table
end

#yytable_ninfObject



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

def yytable_ninf
  @yytable_ninf
end

#yytnameObject

Mapping from symbol number to its name



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

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

#yytokentypeObject

enum yytokentype



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

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



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

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