@@ -26,7 +26,6 @@ class GLL<VertexType, LabelType : ILabel>(
2626 private val createdGSSNodes: HashMap <GSSNode <VertexType >, GSSNode <VertexType >> = HashMap ()
2727 private var parseResult: SPPFNode <VertexType >? = null
2828 private val reachabilityPairs: HashMap <Pair <VertexType , VertexType >, Int > = HashMap ()
29- private val minDistanceRecognisedBySymbol: HashMap <SymbolSPPFNode <VertexType >, Int > = HashMap ()
3029
3130 fun parse (): Pair <SPPFNode <VertexType >? , HashMap<Pair<VertexType, VertexType>, Int>> {
3231 for (startVertex in input.getInputStartVertices()) {
@@ -84,68 +83,6 @@ class GLL<VertexType, LabelType : ILabel>(
8483 return Pair (parseResult, reachabilityPairs)
8584 }
8685
87- private fun minDistance (root : ISPPFNode ): Int {
88- val cycle = HashSet <ISPPFNode >()
89- val visited = HashSet <ISPPFNode >()
90- val stack = ArrayDeque (listOf (root))
91- var curSPPFNode: ISPPFNode
92- var minDistance = 0
93-
94- while (stack.isNotEmpty()) {
95- curSPPFNode = stack.last()
96- visited.add(curSPPFNode)
97-
98- if (! cycle.contains(curSPPFNode)) {
99- cycle.add(curSPPFNode)
100-
101- when (curSPPFNode) {
102- is TerminalSPPFNode <* > -> {
103- minDistance++
104- }
105-
106- is PackedSPPFNode <* > -> {
107- if (curSPPFNode.rightSPPFNode != null ) stack.add(curSPPFNode.rightSPPFNode!! )
108- if (curSPPFNode.leftSPPFNode != null ) stack.add(curSPPFNode.leftSPPFNode!! )
109- }
110-
111- is ItemSPPFNode <* > -> {
112- if (curSPPFNode.kids.isNotEmpty()) {
113- curSPPFNode.kids.findLast {
114- it.rightSPPFNode != curSPPFNode && it.leftSPPFNode != curSPPFNode && ! visited.contains(
115- it
116- )
117- }?.let { stack.add(it) }
118- curSPPFNode.kids.forEach { visited.add(it) }
119- }
120- }
121-
122- is SymbolSPPFNode <* > -> {
123- if (minDistanceRecognisedBySymbol.containsKey(curSPPFNode)) {
124- minDistance + = minDistanceRecognisedBySymbol[curSPPFNode]!!
125- } else {
126- if (curSPPFNode.kids.isNotEmpty()) {
127- curSPPFNode.kids.findLast {
128- it.rightSPPFNode != curSPPFNode && it.leftSPPFNode != curSPPFNode && ! visited.contains(
129- it
130- )
131- }?.let { stack.add(it) }
132- curSPPFNode.kids.forEach { visited.add(it) }
133- }
134- }
135- }
136- }
137- }
138- if (curSPPFNode == stack.last()) {
139- stack.removeLast()
140- cycle.remove(curSPPFNode)
141- }
142- }
143-
144- minDistanceRecognisedBySymbol[root as SymbolSPPFNode <VertexType >] = minDistance
145-
146- return minDistance
147- }
148-
14986 private fun parse (curDescriptor : Descriptor <VertexType >) {
15087 val state = curDescriptor.rsmState
15188 val pos = curDescriptor.inputPosition
@@ -175,7 +112,7 @@ class GLL<VertexType, LabelType : ILabel>(
175112 }
176113
177114 val pair = Pair (leftExtent, rightExtent)
178- val distance = minDistance(curSPPFNode)
115+ val distance = sppf. minDistance(curSPPFNode)
179116
180117 if (reachabilityPairs.containsKey(pair)) {
181118 reachabilityPairs[pair] = minOf(distance, reachabilityPairs[pair]!! )
0 commit comments