|
5 | 5 |
|
6 | 6 | package jflex.generator; |
7 | 7 |
|
8 | | -import java.io.File; |
9 | | -import java.io.PrintWriter; |
10 | | -import java.util.LinkedHashMap; |
11 | | -import java.util.Map; |
12 | 8 | import jflex.base.Build; |
13 | 9 | import jflex.base.Pair; |
14 | | -import jflex.core.AbstractLexScan; |
15 | | -import jflex.core.Action; |
16 | | -import jflex.core.EOFActions; |
17 | | -import jflex.core.LexParse; |
18 | | -import jflex.core.LexScan; |
| 10 | +import jflex.core.*; |
19 | 11 | import jflex.core.unicode.CMapBlock; |
20 | 12 | import jflex.core.unicode.CharClasses; |
21 | 13 | import jflex.dfa.DFA; |
|
26 | 18 | import jflex.option.Options; |
27 | 19 | import jflex.skeleton.Skeleton; |
28 | 20 |
|
| 21 | +import java.io.File; |
| 22 | +import java.io.PrintWriter; |
| 23 | +import java.util.*; |
| 24 | + |
29 | 25 | /** |
30 | 26 | * This class manages the actual code generation, putting the scanner together, filling in skeleton |
31 | 27 | * sections etc. |
@@ -175,8 +171,7 @@ private void emitLookBuffer() { |
175 | 171 | if (!hasGenLookAhead()) return; |
176 | 172 |
|
177 | 173 | println(" /** For the backwards DFA of general lookahead statements */"); |
178 | | - println( |
179 | | - " private boolean [] zzFin = new boolean [Math.min(ZZ_BUFFERSIZE, zzMaxBufferLen())+1];"); |
| 174 | + println(" private BitSet zzFin = null;"); |
180 | 175 | println(); |
181 | 176 | } |
182 | 177 |
|
@@ -428,11 +423,22 @@ private void emitHeader() { |
428 | 423 | private void emitUserCode() { |
429 | 424 | println(scanner.userCode()); |
430 | 425 |
|
| 426 | + List<String> additionalImports = new ArrayList<>(); |
431 | 427 | if (scanner.cup2Compatible()) { |
| 428 | + additionalImports.addAll(Arrays.asList( |
| 429 | + "/* CUP2 imports */", |
| 430 | + "import edu.tum.cup2.scanner.*;", |
| 431 | + "import edu.tum.cup2.grammar.*;" |
| 432 | + )); |
| 433 | + } |
| 434 | + |
| 435 | + if (hasGenLookAhead()) { |
| 436 | + additionalImports.add("import java.util.BitSet;"); |
| 437 | + } |
| 438 | + |
| 439 | + if (!additionalImports.isEmpty()) { |
432 | 440 | println(); |
433 | | - println("/* CUP2 imports */"); |
434 | | - println("import edu.tum.cup2.scanner.*;"); |
435 | | - println("import edu.tum.cup2.grammar.*;"); |
| 441 | + additionalImports.forEach(this::println); |
436 | 442 | println(); |
437 | 443 | } |
438 | 444 | } |
@@ -1116,26 +1122,26 @@ private void emitActions() { |
1116 | 1122 | println(" // general lookahead, find correct zzMarkedPos"); |
1117 | 1123 | println(" { int zzFState = " + dfa.entryState(action.getEntryState()) + ";"); |
1118 | 1124 | println(" int zzFPos = zzStartRead;"); |
1119 | | - println(" if (zzFin.length <= zzBufferL.length) {"); |
1120 | | - println(" zzFin = new boolean[zzBufferL.length+1];"); |
| 1125 | + println(" if (zzFin == null || zzFin.size() <= zzBufferL.length) {"); |
| 1126 | + println(" zzFin = new BitSet(zzBufferL.length+1);"); |
1121 | 1127 | println(" }"); |
1122 | | - println(" boolean zzFinL[] = zzFin;"); |
| 1128 | + println(" BitSet zzFinL = zzFin;"); |
1123 | 1129 | println(" while (zzFState != -1 && zzFPos < zzMarkedPos) {"); |
1124 | | - println(" zzFinL[zzFPos] = ((zzAttrL[zzFState] & 1) == 1);"); |
| 1130 | + println(" zzFinL.set(zzFPos, ((zzAttrL[zzFState] & 1) == 1));"); |
1125 | 1131 | println(" zzInput = Character.codePointAt(zzBufferL, zzFPos, zzMarkedPos);"); |
1126 | 1132 | println(" zzFPos += Character.charCount(zzInput);"); |
1127 | 1133 | println(" zzFState = zzTransL[ zzRowMapL[zzFState] + zzCMap(zzInput) ];"); |
1128 | 1134 | println(" }"); |
1129 | 1135 | println(" if (zzFState != -1) {"); |
1130 | | - println(" zzFinL[zzFPos++] = ((zzAttrL[zzFState] & 1) == 1);"); |
| 1136 | + println(" zzFinL.set(zzFPos++, ((zzAttrL[zzFState] & 1) == 1));"); |
1131 | 1137 | println(" }"); |
1132 | 1138 | println(" while (zzFPos <= zzMarkedPos) {"); |
1133 | | - println(" zzFinL[zzFPos++] = false;"); |
| 1139 | + println(" zzFinL.clear(zzFPos++);"); |
1134 | 1140 | println(" }"); |
1135 | 1141 | println(); |
1136 | 1142 | println(" zzFState = " + dfa.entryState(action.getEntryState() + 1) + ";"); |
1137 | 1143 | println(" zzFPos = zzMarkedPos;"); |
1138 | | - println(" while (!zzFinL[zzFPos] || (zzAttrL[zzFState] & 1) != 1) {"); |
| 1144 | + println(" while (!zzFinL.get(zzFPos) || (zzAttrL[zzFState] & 1) != 1) {"); |
1139 | 1145 | println( |
1140 | 1146 | " zzInput = Character.codePointBefore(zzBufferL, zzFPos, zzStartRead);"); |
1141 | 1147 | println(" zzFPos -= Character.charCount(zzInput);"); |
|
0 commit comments