Class: DFAState

Inherits:
Object show all
Defined in:
lib/antlr4/dfa/DFAState.rb

Overview

/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(state_number = nil, _configs = ATNConfigSet.new()) ⇒ DFAState



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/antlr4/dfa/DFAState.rb', line 41

def initialize(state_number=nil, _configs=ATNConfigSet.new())
    if state_number.nil? then
      @stateNumber = -1
    else
      @stateNumber = state_number
    end
    self.configs = _configs
    # {@code edges[symbol]} points to target of symbol. Shift up by 1 so (-1)
    #  {@link Token#EOF} maps to {@code edges[0]}.
    self.edges = nil
    self.isAcceptState = false
    # if accept state, what ttype do we match or alt do we predict?
    #  This is set to {@link ATN#INVALID_ALT_NUMBER} when {@link #predicates}{@code !=null} or
    #  {@link #requiresFullContext}.
    self.prediction = 0
    self.lexerActionExecutor = nil
    # Indicates that this state was created during SLL prediction that
    # discovered a conflict between the configurations in the state. Future
    # {@link ParserATNSimulator#execATN} invocations immediately jumped doing
    # full context prediction if this field is true.
    self.requiresFullContext = false
    # During SLL parsing, this is a list of predicates associated with the
    #  ATN configurations of the DFA state. When we have predicates,
    #  {@link #requiresFullContext} is {@code false} since full context prediction evaluates predicates
    #  on-the-fly. If this is not null, then {@link #prediction} is
    #  {@link ATN#INVALID_ALT_NUMBER}.
    #
    #  <p>We only use these for non-{@link #requiresFullContext} but conflicting states. That
    #  means we know from the context (it's $ or we don't dip into outer
    #  context) that it's an ambiguity not a conflict.</p>
    #
    #  <p>This list is computed by {@link ParserATNSimulator#predicateDFAState}.</p>
    self.predicates = nil
end

Instance Attribute Details

#configsObject

Returns the value of attribute configs.



39
40
41
# File 'lib/antlr4/dfa/DFAState.rb', line 39

def configs
  @configs
end

#edgesObject

Returns the value of attribute edges.



39
40
41
# File 'lib/antlr4/dfa/DFAState.rb', line 39

def edges
  @edges
end

#isAcceptStateObject

Returns the value of attribute isAcceptState.



39
40
41
# File 'lib/antlr4/dfa/DFAState.rb', line 39

def isAcceptState
  @isAcceptState
end

#lexerActionExecutorObject

Returns the value of attribute lexerActionExecutor.



40
41
42
# File 'lib/antlr4/dfa/DFAState.rb', line 40

def lexerActionExecutor
  @lexerActionExecutor
end

#predicatesObject

Returns the value of attribute predicates.



40
41
42
# File 'lib/antlr4/dfa/DFAState.rb', line 40

def predicates
  @predicates
end

#predictionObject

Returns the value of attribute prediction.



39
40
41
# File 'lib/antlr4/dfa/DFAState.rb', line 39

def prediction
  @prediction
end

#requiresFullContextObject

Returns the value of attribute requiresFullContext.



40
41
42
# File 'lib/antlr4/dfa/DFAState.rb', line 40

def requiresFullContext
  @requiresFullContext
end

#stateNumberObject

Returns the value of attribute stateNumber.



39
40
41
# File 'lib/antlr4/dfa/DFAState.rb', line 39

def stateNumber
  @stateNumber
end

Instance Method Details

#<=>(other) ⇒ Object



91
92
93
# File 'lib/antlr4/dfa/DFAState.rb', line 91

def <=>(other)
  self.configs <=> other.configs
end

#==(other) ⇒ Object



111
112
113
114
115
# File 'lib/antlr4/dfa/DFAState.rb', line 111

def ==(other)
  # compare set of ATN configurations in this set with other
  return true if self.equal?(other)
  other.kind_of?(DFAState) and self.configs==other.configs
end

#eql?(other) ⇒ Boolean

Two DFAState instances are equal if their ATN configuration sets are the same. This method is used to see if a state already exists.

<p>Because the number of alternatives and number of ATN configurations are finite, there is a finite number of DFA states that can be processed. This is necessary to show that the algorithm terminates.</p>

<p>Cannot test the DFA state numbers here because in ParserATNSimulator#addDFAState we need to know if any other state exists that has this exact set of ATN configurations. The #stateNumber is irrelevant.</p>



108
109
110
# File 'lib/antlr4/dfa/DFAState.rb', line 108

def eql?(other)
    self == other
end

#getAltSetObject

Get the set of all alts mentioned by all ATN configurations in this

DFA state.


78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/antlr4/dfa/DFAState.rb', line 78

def getAltSet()
    alts = Set.new
    if not self.configs.nil?
        for c in self.configs do
            alts.add(c.alt)
        end
    end
    if alts.empty?
        return nil
    else
        return alts
    end
end

#hashObject



94
95
96
# File 'lib/antlr4/dfa/DFAState.rb', line 94

def hash()
    self.configs.hash
end

#to_sObject



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/antlr4/dfa/DFAState.rb', line 117

def to_s
    StringIO.open do |buf|
        buf.write(self.stateNumber.to_s)
        buf.write(":")
        buf.write(self.configs.to_s ) 
        if self.isAcceptState then
            buf.write("=>")
            if self.predicates then
                buf.write(self.predicates.to_s)
            else
                buf.write(self.prediction.to_s)
            end
        end
        return buf.string
    end
end