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?.
Instance Method Summary collapse
-
#initialize(states) ⇒ Context
constructor
A new instance of Context.
- #yycheck ⇒ Object
- #yydefact ⇒ Object
- #yydefgoto ⇒ Object
-
#yyfinal ⇒ Object
State number of final (accepted) state.
- #yylast ⇒ Object
-
#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
- #yypact_ninf ⇒ Object
- #yypgoto ⇒ Object
-
#yyr1 ⇒ Object
Mapping from rule number to symbol number of LHS.
-
#yyr2 ⇒ Object
Mapping from rule number to lenght 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
- #yytable_ninf ⇒ Object
-
#yytname ⇒ Object
Mapping from symbol number to its name.
-
#yytokentype ⇒ Object
enum yytokentype.
-
#yytranslate ⇒ Object
YYTRANSLATE.
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
#states ⇒ Object (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
#yycheck ⇒ Object
140 141 142 |
# File 'lib/lrama/context.rb', line 140 def yycheck @check end |
#yydefact ⇒ Object
124 125 126 |
# File 'lib/lrama/context.rb', line 124 def yydefact @yydefact end |
#yydefgoto ⇒ Object
132 133 134 |
# File 'lib/lrama/context.rb', line 132 def yydefgoto @yydefgoto end |
#yyfinal ⇒ Object
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 |
#yylast ⇒ Object
49 50 51 |
# File 'lib/lrama/context.rb', line 49 def yylast @yylast end |
#yymaxutok ⇒ Object
Last token number
74 75 76 |
# File 'lib/lrama/context.rb', line 74 def yymaxutok @states.terms.map(&:token_id).max end |
#yynnts ⇒ Object
Number of nterms
59 60 61 |
# File 'lib/lrama/context.rb', line 59 def yynnts @states.nterms.count end |
#yynrules ⇒ Object
Number of rules
64 65 66 |
# File 'lib/lrama/context.rb', line 64 def yynrules @states.rules.count end |
#yynstates ⇒ Object
Number of states
69 70 71 |
# File 'lib/lrama/context.rb', line 69 def yynstates @states.states.count end |
#yyntokens ⇒ Object
Number of terms
54 55 56 |
# File 'lib/lrama/context.rb', line 54 def yyntokens @states.terms.count end |
#yypact ⇒ Object
120 121 122 |
# File 'lib/lrama/context.rb', line 120 def yypact @base[0...yynstates] end |
#yypact_ninf ⇒ Object
112 113 114 |
# File 'lib/lrama/context.rb', line 112 def yypact_ninf @yypact_ninf end |
#yypgoto ⇒ Object
128 129 130 |
# File 'lib/lrama/context.rb', line 128 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.
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 |
#yyr2 ⇒ Object
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 |
#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.
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 |
#yystos ⇒ Object
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_t ⇒ Object
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 |
#yytable ⇒ Object
136 137 138 |
# File 'lib/lrama/context.rb', line 136 def yytable @table end |
#yytable_ninf ⇒ Object
116 117 118 |
# File 'lib/lrama/context.rb', line 116 def yytable_ninf @yytable_ninf end |
#yytname ⇒ Object
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 |
#yytokentype ⇒ Object
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 |
#yytranslate ⇒ Object
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 |