public void copy(StateSet set) { if (DEBUG) { Out.dump("StateSet.copy(" + set + ") start"); //$NON-NLS-1$ //$NON-NLS-2$ } if (set == null) { for (int i = 0; i < bits.Length; i++) { bits[i] = 0; } return; } if (bits.Length < set.bits.Length) { bits = new long[set.bits.Length]; } else { for (int i = set.bits.Length; i < bits.Length; i++) { bits[i] = 0; } } Array.Copy(set.bits, 0, bits, 0, bits.Length); if (DEBUG) { Out.dump("StateSet.copy(" + set + ") end"); //$NON-NLS-1$ //$NON-NLS-2$ Out.dump("Set is : " + this); //$NON-NLS-1$ } }
public void printBlocks(int [] b, int [] b_f, int [] b_b, int last) { Out.dump("block : " + ToString(b)); Out.dump("b_forward : " + ToString(b_f)); Out.dump("b_backward: " + ToString(b_b)); Out.dump("lastBlock : " + last); int n = numStates + 1; for (int i = n; i <= last; i++) { Out.dump("Block " + (i - n) + " (size " + b[i] + "):"); String line = "{"; int s = b_f[i]; while (s != i) { line = line + (s - 1); int t = s; s = b_f[s]; if (s != i) { line = line + ","; if (b[s] != i) { Out.dump("consistency error for state " + (s - 1) + " (block " + b[s] + ")"); } } if (b_b[s] != t) { Out.dump("consistency error for b_back in state " + (s - 1) + " (back = " + b_b[s] + ", should be = " + t + ")"); } } Out.dump(line + "}"); } }
public void printInvDelta(int [] [] inv_delta, int [] inv_delta_set) { Out.dump("Inverse of transition table: "); for (int s = 0; s < numStates + 1; s++) { Out.dump("State [" + (s - 1) + "]"); for (int c = 0; c < numInput; c++) { String line = "With <" + c + "> in {"; int t = inv_delta[s][c]; while (inv_delta_set[t] != -1) { line += inv_delta_set[t++] - 1; if (inv_delta_set[t] != -1) { line += ","; } } if (inv_delta_set[inv_delta[s][c]] != -1) { Out.dump(line + "}"); } } } }
public bool containsSet(StateSet set) { if (DEBUG) { Out.dump("StateSet.containsSet(" + set + "), this=" + this); //$NON-NLS-1$ //$NON-NLS-2$ } int i; int min = Math.Min(bits.Length, set.bits.Length); for (i = 0; i < min; i++) { if ((bits[i] & set.bits[i]) != set.bits[i]) { return(false); } } for (i = min; i < set.bits.Length; i++) { if (set.bits[i] != 0) { return(false); } } return(true); }
/** * Returns the set of elements that contained are in the specified set * but are not contained in this set. */ public StateSet complement(StateSet set) { if (set == null) { return(null); } StateSet result = new StateSet(); result.bits = new long[set.bits.Length]; int i; int m = Math.Min(bits.Length, set.bits.Length); for (i = 0; i < m; i++) { result.bits[i] = ~bits[i] & set.bits[i]; } if (bits.Length < set.bits.Length) { Array.Copy(set.bits, m, result.bits, m, result.bits.Length - m); } if (DEBUG) { Out.dump("Complement of " + this + Out.NL + "and " + set + Out.NL + " is :" + result); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } return(result); }
/* intersection */ public IntCharSet and(IntCharSet set) { if (DEBUG) { Out.dump("intersection"); Out.dump("this : " + this); Out.dump("other : " + set); } IntCharSet result = new IntCharSet(); int i = 0; // index in this.intervalls int j = 0; // index in set.intervalls int size = intervalls.Count; int setSize = set.intervalls.Count; while (i < size && j < setSize) { Interval x = (Interval)this.intervalls[i]; Interval y = (Interval)set.intervalls[j]; if (x.end < y.start) { i++; continue; } if (y.end < x.start) { j++; continue; } result.intervalls.Add( new Interval( max(x.start, y.start), min(x.end, y.end) ) ); if (x.end >= y.end) { j++; } if (y.end >= x.end) { i++; } } if (DEBUG) { Out.dump("result: " + result); } return(result); }
/** * Updates the current partition, so that the specified set of characters * gets a new character class. * * Characters that are elements of <code>set</code> are not in the same * equivalence class with characters that are not elements of <code>set</code>. * * @param set the set of characters to distinguish from the rest * @param caseless if true upper/lower/title case are considered equivalent */ public void makeClass(IntCharSet set, bool caseless) { if (caseless) { set = set.getCaseless(); } if (DEBUG) { Out.dump("makeClass(" + set + ")"); dump(); } try { int oldSize = classes.Count; for (int i = 0; i < oldSize; i++) { IntCharSet x = (IntCharSet)classes[i]; if (x.Equals(set)) { return; } IntCharSet and = x.and(set); if (and.containsElements()) { if (x.Equals(and)) { set.sub(and); continue; } else if (set.Equals(and)) { x.sub(and); classes.Add(and); return; } set.sub(and); x.sub(and); classes.Add(and); } } } finally { if (DEBUG) { Out.dump("makeClass(..) finished"); dump(); } } }
/** * @throws ClassCastException if b is not a StateSet * @throws NullPointerException if b is null */ public override bool Equals(Object b) { int i = 0; int l1, l2; StateSet set = (StateSet)b; if (DEBUG) { Out.dump("StateSet.equals(" + set + "), this=" + this); //$NON-NLS-1$ //$NON-NLS-2$ } l1 = bits.Length; l2 = set.bits.Length; if (l1 <= l2) { while (i < l1) { if (bits[i] != set.bits[i]) { return(false); } i++; } while (i < l2) { if (set.bits[i++] != 0) { return(false); } } } else { while (i < l2) { if (bits[i] != set.bits[i]) { return(false); } i++; } while (i < l1) { if (bits[i++] != 0) { return(false); } } } return(true); }
/** * Returns an array that contains the character class codes of all characters * in the specified set of input characters. */ private int [] getClassCodes(IntCharSet set, bool negate) { if (DEBUG) { Out.dump("getting class codes for " + set); if (negate) { Out.dump("[negated]"); } } int size = classes.Count; // [fixme: optimize] int[] temp = new int [size]; int length = 0; for (int i = 0; i < size; i++) { IntCharSet x = (IntCharSet)classes[i]; if (negate) { if (!set.and(x).containsElements()) { temp[length++] = i; if (DEBUG) { Out.dump("code " + i); } } } else { if (set.and(x).containsElements()) { temp[length++] = i; if (DEBUG) { Out.dump("code " + i); } } } } int[] result = new int [length]; Array.Copy(temp, 0, result, 0, length); return(result); }
public void printTable(bool [] [] equiv) { Out.dump("Equivalence table is : "); for (int i = 1; i < numStates; i++) { String line = i + " :"; for (int j = 0; j < i; j++) { if (equiv[i][j]) { line += " E"; } else { line += " x"; } } Out.dump(line); } }
public void addState(int state) { if (DEBUG) { Out.dump("StateSet.addState(" + state + ") start"); //$NON-NLS-1$ //$NON-NLS-2$ Out.dump("Set is : " + this); //$NON-NLS-1$ } int index = state >> BITS; if (index >= bits.Length) { resize(state); } bits[index] |= (1L << (state & MASK)); if (DEBUG) { Out.dump("StateSet.addState(" + state + ") end"); //$NON-NLS-1$ //$NON-NLS-2$ Out.dump("Set is : " + this); //$NON-NLS-1$ } }
public void add(StateSet set) { if (DEBUG) { Out.dump("StateSet.add(" + set + ") start"); //$NON-NLS-1$ //$NON-NLS-2$ } if (set == null) { return; } long[] tbits; long[] sbits = set.bits; int sbitsl = sbits.Length; if (bits.Length < sbitsl) { tbits = new long[sbitsl]; Array.Copy(bits, 0, tbits, 0, bits.Length); } else { tbits = this.bits; } for (int i = 0; i < sbitsl; i++) { tbits[i] |= sbits[i]; } this.bits = tbits; if (DEBUG) { Out.dump("StateSet.add(" + set + ") end"); //$NON-NLS-1$ //$NON-NLS-2$ Out.dump("Set is : " + this); //$NON-NLS-1$ } }
public void printL(int [] l_f, int [] l_b, int anchor) { String l = "L = {"; int bc = l_f[anchor]; while (bc != anchor) { int b = bc / numInput; int c = bc % numInput; l += "(" + b + "," + c + ")"; int old_bc = bc; bc = l_f[bc]; if (bc != anchor) { l += ","; } if (l_b[bc] != old_bc) { Out.dump("consistency error for (" + b + "," + c + ")"); } } Out.dump(l + "}"); }
/* complement */ /* prec: this.contains(set), set != null */ public void sub(IntCharSet set) { if (DEBUG) { Out.dump("complement"); Out.dump("this : " + this); Out.dump("other : " + set); } int i = 0; // index in this.intervalls int j = 0; // index in set.intervalls int setSize = set.intervalls.Count; while (i < intervalls.Count && j < setSize) { Interval x = (Interval)this.intervalls[i]; Interval y = (Interval)set.intervalls[j]; if (DEBUG) { Out.dump("this : " + this); Out.dump("this [" + i + "] : " + x); Out.dump("other [" + j + "] : " + y); } if (x.end < y.start) { i++; continue; } if (y.end < x.start) { j++; continue; } // x.end >= y.start && y.end >= x.start -> // x.end <= y.end && x.start >= y.start (prec) if (x.start == y.start && x.end == y.end) { intervalls.RemoveAt(i); j++; continue; } // x.end <= y.end && x.start >= y.start && // (x.end < y.end || x.start > y.start) -> // x.start < x.end if (x.start == y.start) { x.start = (char)(y.end + 1); j++; continue; } if (x.end == y.end) { x.end = (char)(y.start - 1); i++; j++; continue; } intervalls.Insert(i, new Interval(x.start, (char)(y.start - 1))); x.start = (char)(y.end + 1); i++; j++; } if (DEBUG) { Out.dump("result: " + this); } }
public const String version = "1.4"; //$NON-NLS-1$ /** * Generates a scanner for the specified input file. * * @param inputFile a file containing a lexical specification * to generate a scanner for. */ public static void generate(File inputFile) { Out.resetCounters(); Timer totalTime = new Timer(); Timer time = new Timer(); LexScan scanner = null; LexParse parser = null; TextReader inputReader = null; totalTime.start(); try { Out.println(ErrorMessages.READING, inputFile.ToString()); inputReader = new StreamReader(inputFile); scanner = new LexScan(inputReader); scanner.setFile(inputFile); parser = new LexParse(scanner); } catch (FileNotFoundException) { Out.error(ErrorMessages.CANNOT_OPEN, inputFile.ToString()); throw new GeneratorException(); } try { NFA nfa = (NFA)parser.parse().value; Out.checkErrors(); if (Options.dump) { Out.dump(ErrorMessages.get(ErrorMessages.NFA_IS) + Out.NL + nfa + Out.NL); } if (Options.dot) { nfa.writeDot(Emitter.normalize("nfa.dot", null)); //$NON-NLS-1$ } Out.println(ErrorMessages.NFA_STATES, nfa.numStates); time.start(); DFA dfa = nfa.getDFA(); time.stop(); Out.time(ErrorMessages.DFA_TOOK, time); dfa.checkActions(scanner, parser); nfa = null; if (Options.dump) { Out.dump(ErrorMessages.get(ErrorMessages.DFA_IS) + Out.NL + dfa + Out.NL); } if (Options.dot) { dfa.writeDot(Emitter.normalize("dfa-big.dot", null)); //$NON-NLS-1$ } time.start(); dfa.minimize(); time.stop(); Out.time(ErrorMessages.MIN_TOOK, time); if (Options.dump) { Out.dump(ErrorMessages.get(ErrorMessages.MIN_DFA_IS) + Out.NL + dfa); } if (Options.dot) { dfa.writeDot(Emitter.normalize("dfa-min.dot", null)); //$NON-NLS-1$ } time.start(); Emitter e = new Emitter(inputFile, parser, dfa); e.emit(); time.stop(); Out.time(ErrorMessages.WRITE_TOOK, time); totalTime.stop(); Out.time(ErrorMessages.TOTAL_TIME, totalTime); } catch (ScannerException e) { Out.error(e.file, e.message, e.line, e.column); throw new GeneratorException(); } catch (MacroException e) { Out.error(e.Message); throw new GeneratorException(); } catch (IOException e) { Out.error(ErrorMessages.IO_ERROR, e.ToString()); throw new GeneratorException(); } catch (OutOfMemoryException) { Out.error(ErrorMessages.OUT_OF_MEMORY); throw new GeneratorException(); } catch (GeneratorException) { throw new GeneratorException(); } catch (Exception e) { Out.error(e.ToString()); throw new GeneratorException(); } }
public void dumpTable() { Out.dump(ToString()); }