1 20 package JFlex; 21 22 import java.io.File ; 23 24 32 public final class SemCheck { 33 34 private static Macros macros; 36 private static char maxChar; 37 38 39 50 public static void check(RegExps rs, Macros m, char max, File f) { 51 macros = m; 52 maxChar = max; 53 54 int num = rs.getNum(); 55 for (int i = 0; i < num; i++) { 56 RegExp r = rs.getRegExp(i); 57 RegExp l = rs.getLookAhead(i); 58 59 if (!checkLookAhead(r,l)) { 60 Out.warning(f, ErrorMessages.LOOKAHEAD_ERROR, rs.getLine(i), -1); 61 } 62 } 63 } 64 65 66 81 private static boolean checkLookAhead(RegExp r1, RegExp r2) { 82 return r2 == null || length(r1) > 0; 83 } 84 85 86 91 private static int length(RegExp re) { 92 RegExp2 r; 93 94 switch (re.type) { 95 96 case sym.BAR: { 97 r = (RegExp2) re; 98 int l1 = length(r.r1); 99 if (l1 < 0) return -1; 100 int l2 = length(r.r2); 101 102 if (l1 == l2) 103 return l1; 104 else 105 return -1; 106 } 107 108 case sym.CONCAT: { 109 r = (RegExp2) re; 110 int l1 = length(r.r1); 111 if (l1 < 0) return -1; 112 int l2 = length(r.r2); 113 if (l2 < 0) return -1; 114 return l1+l2; 115 } 116 117 case sym.STAR: 118 case sym.PLUS: 119 case sym.QUESTION: 120 return -1; 121 122 case sym.CCLASS: 123 case sym.CCLASSNOT: 124 case sym.CHAR: 125 case sym.CHAR_I: 126 return 1; 127 128 case sym.STRING: 129 case sym.STRING_I: { 130 String content = (String ) ((RegExp1) re).content; 131 return content.length(); 132 } 133 134 case sym.TILDE: 135 case sym.BANG: 136 return -1; 138 139 case sym.MACROUSE: 140 return length(macros.getDefinition((String ) ((RegExp1) re).content)); 141 } 142 143 throw new Error ("Unkown expression type "+re.type+" in "+re); } 145 } 146 | Popular Tags |