Class: Racc::States

Inherits:
Object show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/racc/state.rb

Overview

A table of LALR states.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(grammar, debug_flags = DebugFlags.new) ⇒ States

Returns a new instance of States.



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/racc/state.rb', line 25

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

#actionsObject (readonly)

Returns the value of attribute actions.



39
40
41
# File 'lib/racc/state.rb', line 39

def actions
  @actions
end

#grammarObject (readonly)

Returns the value of attribute grammar.



38
39
40
# File 'lib/racc/state.rb', line 38

def grammar
  @grammar
end

Instance Method Details

#[](i) ⇒ Object



51
52
53
# File 'lib/racc/state.rb', line 51

def [](i)
  @states[i]
end

#dfaObject



196
197
198
199
200
201
202
# File 'lib/racc/state.rb', line 196

def dfa
  return self if @dfa_computed
  nfa
  compute_dfa
  @dfa_computed = true
  self
end

#each_index(&block) ⇒ Object



61
62
63
# File 'lib/racc/state.rb', line 61

def each_index(&block)
  @states.each_index(&block)
end

#each_state(&block) ⇒ Object Also known as: each



55
56
57
# File 'lib/racc/state.rb', line 55

def each_state(&block)
  @states.each(&block)
end

#inspectObject Also known as: to_s



45
46
47
# File 'lib/racc/state.rb', line 45

def inspect
  '#<state table>'
end

#n_rrconflictsObject



88
89
90
# File 'lib/racc/state.rb', line 88

def n_rrconflicts
  @n_rrconflicts ||= inject(0) {|sum, st| sum + st.n_rrconflicts }
end

#n_srconflictsObject



80
81
82
# File 'lib/racc/state.rb', line 80

def n_srconflicts
  @n_srconflicts ||= inject(0) {|sum, st| sum + st.n_srconflicts }
end

#nfaObject



102
103
104
105
106
107
# File 'lib/racc/state.rb', line 102

def nfa
  return self if @nfa_computed
  compute_nfa
  @nfa_computed = true
  self
end

#rrconflict_exist?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/racc/state.rb', line 84

def rrconflict_exist?
  n_rrconflicts() != 0
end

#should_report_srconflict?Boolean

Returns:

  • (Boolean)


71
72
73
74
# File 'lib/racc/state.rb', line 71

def should_report_srconflict?
  srconflict_exist? and
      (n_srconflicts() != @grammar.n_expected_srconflicts)
end

#sizeObject



41
42
43
# File 'lib/racc/state.rb', line 41

def size
  @states.size
end

#srconflict_exist?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/racc/state.rb', line 76

def srconflict_exist?
  n_srconflicts() != 0
end

#state_transition_tableObject



92
93
94
# File 'lib/racc/state.rb', line 92

def state_transition_table
  @state_transition_table ||= StateTransitionTable.generate(self.dfa)
end