1 20 package JFlex; 21 22 import java.util.*; 23 24 25 31 public class RegExps { 32 33 34 Vector lines; 35 36 37 Vector states; 38 39 40 Vector regExps; 41 42 43 Vector actions; 44 45 46 Vector BOL; 47 48 49 Vector look; 50 51 public RegExps() { 52 states = new Vector(); 53 regExps = new Vector(); 54 actions = new Vector(); 55 BOL = new Vector(); 56 look = new Vector(); 57 lines = new Vector(); 58 } 59 60 public int insert(int line, Vector stateList, RegExp regExp, Action action, 61 Boolean isBOL, RegExp lookAhead) { 62 if (Options.DEBUG) { 63 Out.debug("Inserting regular expression with statelist :"+Out.NL+stateList); Out.debug("and action code :"+Out.NL+action.content+Out.NL); Out.debug("expression :"+Out.NL+regExp); } 67 68 states.addElement(stateList); 69 regExps.addElement(regExp); 70 actions.addElement(action); 71 BOL.addElement(isBOL); 72 look.addElement(lookAhead); 73 lines.addElement(new Integer (line)); 74 75 return states.size()-1; 76 } 77 78 public int insert(Vector stateList, Action action) { 79 80 if (Options.DEBUG) { 81 Out.debug("Inserting eofrule with statelist :"+Out.NL+stateList); Out.debug("and action code :"+Out.NL+action.content+Out.NL); } 84 85 states.addElement(stateList); 86 regExps.addElement(null); 87 actions.addElement(action); 88 BOL.addElement(null); 89 look.addElement(null); 90 lines.addElement(null); 91 92 return states.size()-1; 93 } 94 95 public void addStates(int regNum, Vector newStates) { 96 Enumeration s = newStates.elements(); 97 98 while (s.hasMoreElements()) 99 ((Vector)states.elementAt(regNum)).addElement(s.nextElement()); 100 } 101 102 public int getNum() { 103 return states.size(); 104 } 105 106 public boolean isBOL(int num) { 107 return ((Boolean ) BOL.elementAt(num)).booleanValue(); 108 } 109 110 public RegExp getLookAhead(int num) { 111 return (RegExp) look.elementAt(num); 112 } 113 114 public boolean isEOF(int num) { 115 return BOL.elementAt(num) == null; 116 } 117 118 public Vector getStates(int num) { 119 return (Vector) states.elementAt(num); 120 } 121 122 public RegExp getRegExp(int num) { 123 return (RegExp) regExps.elementAt(num); 124 } 125 126 public int getLine(int num) { 127 return ((Integer ) lines.elementAt(num)).intValue(); 128 } 129 130 public void checkActions() { 131 if ( actions.elementAt(actions.size()-1) == null ) { 132 Out.error(ErrorMessages.NO_LAST_ACTION); 133 throw new GeneratorException(); 134 } 135 } 136 137 public Action getAction(int num) { 138 while ( num < actions.size() && actions.elementAt(num) == null ) 139 num++; 140 141 return (Action) actions.elementAt(num); 142 } 143 144 public int NFASize(Macros macros) { 145 int size = 0; 146 Enumeration e = regExps.elements(); 147 while (e.hasMoreElements()) { 148 RegExp r = (RegExp) e.nextElement(); 149 if (r != null) size += r.size(macros); 150 } 151 e = look.elements(); 152 while (e.hasMoreElements()) { 153 RegExp r = (RegExp) e.nextElement(); 154 if (r != null) size += r.size(macros); 155 } 156 return size; 157 } 158 } 159 | Popular Tags |