Class: Lrama::Context
- Inherits:
-
Object
- Object
- Lrama::Context
- 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
-
#states ⇒ Object
readonly
TODO: It might be better to pass ‘states` to Output directly?.
-
#yydefact ⇒ Object
readonly
TODO: It might be better to pass ‘states` to Output directly?.
-
#yydefgoto ⇒ Object
readonly
TODO: It might be better to pass ‘states` to Output directly?.
-
#yylast ⇒ Object
readonly
TODO: It might be better to pass ‘states` to Output directly?.
-
#yypact_ninf ⇒ Object
readonly
TODO: It might be better to pass ‘states` to Output directly?.
-
#yytable_ninf ⇒ Object
readonly
TODO: It might be better to pass ‘states` to Output directly?.
Instance Method Summary collapse
-
#initialize(states) ⇒ Context
constructor
A new instance of Context.
- #yycheck ⇒ Object
-
#yyfinal ⇒ Object
State number of final (accepted) state.
-
#yymaxutok ⇒ Object
Last token number.
-
#yynnts ⇒ Object
Number of nterms.
-
#yynrules ⇒ Object
Number of rules.
-
#yynstates ⇒ Object
Number of states.
-
#yyntokens ⇒ Object
Number of terms.
- #yypact ⇒ Object
- #yypgoto ⇒ Object
-
#yyr1 ⇒ Object
Mapping from rule number to symbol number of LHS.
-
#yyr2 ⇒ Object
Mapping from rule number to length of RHS.
-
#yyrline ⇒ Object
Mapping from rule number to line number of the rule is defined.
- #yystos ⇒ Object
-
#yysymbol_kind_t ⇒ Object
enum yysymbol_kind_t.
- #yytable ⇒ Object
-
#yytname ⇒ Object
Mapping from symbol number to its name.
-
#yytokentype ⇒ Object
enum yytokentype.
-
#yytranslate ⇒ Object
YYTRANSLATE.
- #yytranslate_inverted ⇒ Object
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
#states ⇒ Object (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 |
#yydefact ⇒ Object (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 |
#yydefgoto ⇒ Object (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 |
#yylast ⇒ Object (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_ninf ⇒ Object (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_ninf ⇒ Object (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
#yycheck ⇒ Object
132 133 134 |
# File 'lib/lrama/context.rb', line 132 def yycheck @check end |
#yyfinal ⇒ Object
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 |
#yymaxutok ⇒ Object
Last token number
72 73 74 |
# File 'lib/lrama/context.rb', line 72 def yymaxutok @states.terms.map(&:token_id).max end |
#yynnts ⇒ Object
Number of nterms
57 58 59 |
# File 'lib/lrama/context.rb', line 57 def yynnts @states.nterms.count end |
#yynrules ⇒ Object
Number of rules
62 63 64 |
# File 'lib/lrama/context.rb', line 62 def yynrules @states.rules.count end |
#yynstates ⇒ Object
Number of states
67 68 69 |
# File 'lib/lrama/context.rb', line 67 def yynstates @states.states.count end |
#yyntokens ⇒ Object
Number of terms
52 53 54 |
# File 'lib/lrama/context.rb', line 52 def yyntokens @states.terms.count end |
#yypact ⇒ Object
120 121 122 |
# File 'lib/lrama/context.rb', line 120 def yypact @base[0...yynstates] end |
#yypgoto ⇒ Object
124 125 126 |
# File 'lib/lrama/context.rb', line 124 def yypgoto @base[yynstates..-1] end |
#yyr1 ⇒ Object
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 |
#yyr2 ⇒ Object
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 |
#yyrline ⇒ Object
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 |
#yystos ⇒ Object
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_t ⇒ Object
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 |
#yytable ⇒ Object
128 129 130 |
# File 'lib/lrama/context.rb', line 128 def yytable @table end |
#yytname ⇒ Object
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 |
#yytokentype ⇒ Object
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 |
#yytranslate ⇒ Object
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_inverted ⇒ Object
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 |