1 18 19 package org.sablecc.sablecc.automaton; 20 21 import java.util.SortedMap ; 22 import java.util.TreeMap ; 23 24 import org.sablecc.sablecc.exception.InternalException; 25 26 31 class NfaCombineResult<T extends Comparable <? super T>> { 32 33 34 private Nfa<T> newNfa; 35 36 37 private Nfa<T> oldNfa1; 38 39 43 private SortedMap <NfaState<T>, NfaState<T>> oldNfa1StateMap = new TreeMap <NfaState<T>, NfaState<T>>(); 44 45 46 private Nfa<T> oldNfa2; 47 48 52 private SortedMap <NfaState<T>, NfaState<T>> oldNfa2StateMap = new TreeMap <NfaState<T>, NfaState<T>>(); 53 54 72 NfaCombineResult( 73 Nfa<T> newNfa, 74 Nfa<T> oldNfa1, 75 SortedMap <NfaState<T>, NfaState<T>> oldNfa1StateMap, 76 Nfa<T> oldNfa2, 77 SortedMap <NfaState<T>, NfaState<T>> oldNfa2StateMap) { 78 79 if (newNfa == null) { 80 throw new InternalException("newNfa may not be null"); 81 } 82 83 if (oldNfa1 == null) { 84 throw new InternalException("oldNfa1 may not be null"); 85 } 86 87 if (oldNfa1StateMap == null) { 88 throw new InternalException("oldNfa1StateMap may not be null"); 89 } 90 91 if (oldNfa2 == null) { 92 throw new InternalException("oldNfa2 may not be null"); 93 } 94 95 if (oldNfa2StateMap == null) { 96 throw new InternalException("oldNfa2StateMap may not be null"); 97 } 98 99 for (NfaState<T> oldState : oldNfa1.getStates()) { 100 if (oldNfa1StateMap.get(oldState) == null) { 101 throw new InternalException("invalid oldNfa1StateMap"); 102 } 103 } 104 105 for (NfaState<T> oldState : oldNfa2.getStates()) { 106 if (oldNfa2StateMap.get(oldState) == null) { 107 throw new InternalException("invalid oldNfa2StateMap"); 108 } 109 } 110 111 this.newNfa = newNfa; 112 this.oldNfa1 = oldNfa1; 113 this.oldNfa1StateMap = oldNfa1StateMap; 114 this.oldNfa2 = oldNfa2; 115 this.oldNfa2StateMap = oldNfa2StateMap; 116 } 117 118 123 Nfa<T> getNewNfa() { 124 125 return this.newNfa; 126 } 127 128 140 NfaState<T> getNewNfa1State( 141 NfaState<T> oldState) { 142 143 if (oldState == null) { 144 throw new InternalException("oldState may not be null"); 145 } 146 147 if (oldState.getNfa() != this.oldNfa1) { 148 throw new InternalException("invalid oldState"); 149 } 150 151 return this.oldNfa1StateMap.get(oldState); 152 } 153 154 166 NfaState<T> getNewNfa2State( 167 NfaState<T> oldState) { 168 169 if (oldState == null) { 170 throw new InternalException("oldState may not be null"); 171 } 172 173 if (oldState.getNfa() != this.oldNfa2) { 174 throw new InternalException("invalid oldState"); 175 } 176 177 return this.oldNfa2StateMap.get(oldState); 178 } 179 180 186 NfaState<T> getNewNfa1StartState() { 187 188 return this.oldNfa1StateMap.get(this.oldNfa1.getStartState()); 189 } 190 191 197 NfaState<T> getNewNfa2StartState() { 198 199 return this.oldNfa2StateMap.get(this.oldNfa2.getStartState()); 200 } 201 202 208 NfaState<T> getNewNfa1AcceptState() { 209 210 return this.oldNfa1StateMap.get(this.oldNfa1.getAcceptState()); 211 } 212 213 219 NfaState<T> getNewNfa2AcceptState() { 220 221 return this.oldNfa2StateMap.get(this.oldNfa2.getAcceptState()); 222 } 223 } 224 | Popular Tags |