1 20 21 package JFlex; 22 23 import java.util.*; 24 25 26 32 public class EOFActions { 33 34 35 private Hashtable actions = new Hashtable(); 36 private Action defaultAction; 37 private int numLexStates; 38 39 public void setNumLexStates(int num) { 40 numLexStates = num; 41 } 42 43 public void add(Vector stateList, Action action) { 44 45 if (stateList != null && stateList.size() > 0) { 46 Enumeration states = stateList.elements(); 47 48 while (states.hasMoreElements()) 49 add( (Integer ) states.nextElement(), action ); 50 } 51 else { 52 defaultAction = action.getHigherPriority(defaultAction); 53 54 for (int i = 0; i < numLexStates; i++) { 55 Integer state = new Integer (i); 56 if ( actions.get(state) != null ) { 57 Action oldAction = (Action) actions.get(state); 58 actions.put(state, oldAction.getHigherPriority(action)); 59 } 60 } 61 } 62 } 63 64 public void add(Integer state, Action action) { 65 if ( actions.get(state) == null ) 66 actions.put(state, action); 67 else { 68 Action oldAction = (Action) actions.get(state); 69 actions.put(state, oldAction.getHigherPriority(action)); 70 } 71 } 72 73 public boolean isEOFAction(Object a) { 74 if (a == defaultAction) return true; 75 76 Enumeration e = actions.elements(); 77 while ( e.hasMoreElements() ) 78 if (a == e.nextElement()) return true; 79 80 return false; 81 } 82 83 public Action getAction(int state) { 84 return (Action) actions.get(new Integer (state)); 85 } 86 87 public Action getDefault() { 88 return defaultAction; 89 } 90 91 public int numActions() { 92 return actions.size(); 93 } 94 } 95 | Popular Tags |