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.
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/racc/state.rb', line 24 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.
38 39 40 |
# File 'lib/racc/state.rb', line 38 def actions @actions end |
#grammar ⇒ Object (readonly)
Returns the value of attribute grammar.
37 38 39 |
# File 'lib/racc/state.rb', line 37 def grammar @grammar end |
Instance Method Details
#[](i) ⇒ Object
50 51 52 |
# File 'lib/racc/state.rb', line 50 def [](i) @states[i] end |
#dfa ⇒ Object
195 196 197 198 199 200 201 |
# File 'lib/racc/state.rb', line 195 def dfa return self if @dfa_computed nfa compute_dfa @dfa_computed = true self end |
#each_index(&block) ⇒ Object
60 61 62 |
# File 'lib/racc/state.rb', line 60 def each_index(&block) @states.each_index(&block) end |
#each_state(&block) ⇒ Object Also known as: each
54 55 56 |
# File 'lib/racc/state.rb', line 54 def each_state(&block) @states.each(&block) end |
#inspect ⇒ Object Also known as: to_s
44 45 46 |
# File 'lib/racc/state.rb', line 44 def inspect '#<state table>' end |
#n_rrconflicts ⇒ Object
87 88 89 |
# File 'lib/racc/state.rb', line 87 def n_rrconflicts @n_rrconflicts ||= inject(0) {|sum, st| sum + st.n_rrconflicts } end |
#n_srconflicts ⇒ Object
79 80 81 |
# File 'lib/racc/state.rb', line 79 def n_srconflicts @n_srconflicts ||= inject(0) {|sum, st| sum + st.n_srconflicts } end |
#nfa ⇒ Object
101 102 103 104 105 106 |
# File 'lib/racc/state.rb', line 101 def nfa return self if @nfa_computed compute_nfa @nfa_computed = true self end |
#rrconflict_exist? ⇒ Boolean
83 84 85 |
# File 'lib/racc/state.rb', line 83 def rrconflict_exist? n_rrconflicts() != 0 end |
#should_report_srconflict? ⇒ Boolean
70 71 72 73 |
# File 'lib/racc/state.rb', line 70 def should_report_srconflict? srconflict_exist? and (n_srconflicts() != @grammar.n_expected_srconflicts) end |
#size ⇒ Object
40 41 42 |
# File 'lib/racc/state.rb', line 40 def size @states.size end |
#srconflict_exist? ⇒ Boolean
75 76 77 |
# File 'lib/racc/state.rb', line 75 def srconflict_exist? n_srconflicts() != 0 end |
#state_transition_table ⇒ Object
91 92 93 |
# File 'lib/racc/state.rb', line 91 def state_transition_table @state_transition_table ||= StateTransitionTable.generate(self.dfa) end |