Class: Racc::States
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/racc/state.rb
Overview
A table of LALR states.
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#grammar ⇒ Object
readonly
Returns the value of attribute grammar.
Instance Method Summary collapse
- #[](i) ⇒ Object
- #dfa ⇒ Object
- #each_index(&block) ⇒ Object
- #each_state(&block) ⇒ Object (also: #each)
-
#initialize(grammar, debug_flags = DebugFlags.new) ⇒ States
constructor
A new instance of States.
- #inspect ⇒ Object (also: #to_s)
- #n_rrconflicts ⇒ Object
- #n_srconflicts ⇒ Object
- #nfa ⇒ Object
- #rrconflict_exist? ⇒ Boolean
- #should_report_srconflict? ⇒ Boolean
- #size ⇒ Object
- #srconflict_exist? ⇒ Boolean
- #state_transition_table ⇒ Object
Constructor Details
#initialize(grammar, debug_flags = DebugFlags.new) ⇒ States
Returns a new instance of States.
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/racc/state.rb', line 22 def initialize(grammar, debug_flags = DebugFlags.new) @grammar = grammar @symboltable = grammar.symboltable @d_state = debug_flags.state @d_la = debug_flags.la @d_prec = debug_flags.prec @states = [] @statecache = {} @actions = ActionTable.new(@grammar, self) @nfa_computed = false @dfa_computed = false end |
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
36 37 38 |
# File 'lib/racc/state.rb', line 36 def actions @actions end |
#grammar ⇒ Object (readonly)
Returns the value of attribute grammar.
35 36 37 |
# File 'lib/racc/state.rb', line 35 def grammar @grammar end |
Instance Method Details
#[](i) ⇒ Object
48 49 50 |
# File 'lib/racc/state.rb', line 48 def [](i) @states[i] end |
#dfa ⇒ Object
193 194 195 196 197 198 199 |
# File 'lib/racc/state.rb', line 193 def dfa return self if @dfa_computed nfa compute_dfa @dfa_computed = true self end |
#each_index(&block) ⇒ Object
58 59 60 |
# File 'lib/racc/state.rb', line 58 def each_index(&block) @states.each_index(&block) end |
#each_state(&block) ⇒ Object Also known as: each
52 53 54 |
# File 'lib/racc/state.rb', line 52 def each_state(&block) @states.each(&block) end |
#inspect ⇒ Object Also known as: to_s
42 43 44 |
# File 'lib/racc/state.rb', line 42 def inspect '#<state table>' end |
#n_rrconflicts ⇒ Object
85 86 87 |
# File 'lib/racc/state.rb', line 85 def n_rrconflicts @n_rrconflicts ||= inject(0) {|sum, st| sum + st.n_rrconflicts } end |
#n_srconflicts ⇒ Object
77 78 79 |
# File 'lib/racc/state.rb', line 77 def n_srconflicts @n_srconflicts ||= inject(0) {|sum, st| sum + st.n_srconflicts } end |
#nfa ⇒ Object
99 100 101 102 103 104 |
# File 'lib/racc/state.rb', line 99 def nfa return self if @nfa_computed compute_nfa @nfa_computed = true self end |
#rrconflict_exist? ⇒ Boolean
81 82 83 |
# File 'lib/racc/state.rb', line 81 def rrconflict_exist? n_rrconflicts() != 0 end |
#should_report_srconflict? ⇒ Boolean
68 69 70 71 |
# File 'lib/racc/state.rb', line 68 def should_report_srconflict? srconflict_exist? and (n_srconflicts() != @grammar.n_expected_srconflicts) end |
#size ⇒ Object
38 39 40 |
# File 'lib/racc/state.rb', line 38 def size @states.size end |
#srconflict_exist? ⇒ Boolean
73 74 75 |
# File 'lib/racc/state.rb', line 73 def srconflict_exist? n_srconflicts() != 0 end |
#state_transition_table ⇒ Object
89 90 91 |
# File 'lib/racc/state.rb', line 89 def state_transition_table @state_transition_table ||= StateTransitionTable.generate(self.dfa) end |