/** Make a deep copy of everything in this object */ public Object clone() { Lookahead p = null; try { p = (Lookahead)super.clone(); p.fset = (BitSet)fset.clone(); p.cycle = cycle; // strings are immutable if (epsilonDepth != null) { p.epsilonDepth = (BitSet)epsilonDepth.clone(); } } catch (CloneNotSupportedException e) { throw new InternalError(); } return p; }
public BitSet not() { BitSet s = (BitSet)this.clone(); s.notInPlace(); return s; }
public BitSet and(BitSet a) { BitSet s = (BitSet)this.clone(); s.andInPlace(a); return s; }
/** return this | a in a new set */ public BitSet or(BitSet a) { BitSet s = (BitSet)this.clone(); s.orInPlace(a); return s; }
public void combineWith(Lookahead q) { if (cycle == null) { // track at least one cycle cycle = q.cycle; } if (q.containsEpsilon()) { hasEpsilon = true; } // combine epsilon depths if (epsilonDepth != null) { if (q.epsilonDepth != null) { epsilonDepth.orInPlace(q.epsilonDepth); } } else if (q.epsilonDepth != null) { epsilonDepth = (BitSet)q.epsilonDepth.clone(); } fset.orInPlace(q.fset); }
public Lookahead look(int k, WildcardElement wc) { if (DEBUG_ANALYZER) System.out.println("look(" + k + "," + wc + ")"); // Skip until analysis hits k==1 if (k > 1) { return wc.next.look(k - 1); } BitSet b; if (lexicalAnalysis) { // Copy the character vocabulary b = (BitSet)((LexerGrammar)grammar).charVocabulary.clone(); } else { b = new BitSet(1); // Invert the lookahead set against the token vocabulary int maxToken = grammar.tokenManager.maxTokenType(); b.notInPlace(Token.MIN_USER_TYPE, maxToken); if (DEBUG_ANALYZER) System.out.println("look(" + k + "," + wc + ") after not: " + b); } // Remove prediction sets from competing alternatives // removeCompetingPredictionSets(b, wc); return new Lookahead(b); }
/** Add a bitset to the list of bitsets to be generated. * if the bitset is already in the list, ignore the request. * Always adds the bitset to the end of the list, so the * caller can rely on the position of bitsets in the list. * The returned position can be used to format the bitset * name, since it is invariant. * @param p Bit set to mark for code generation * @param forParser true if the bitset is used for the parser, false for the lexer * @return The position of the bitset in the list. */ protected int markBitsetForGen(BitSet p) { // Is the bitset (or an identical one) already marked for gen? for (int i = 0; i < bitsetsUsed.size(); i++) { BitSet set = (BitSet)bitsetsUsed.elementAt(i); if (p.equals(set)) { // Use the identical one already stored return i; } } // Add the new bitset bitsetsUsed.appendElement(p.clone()); return bitsetsUsed.size() - 1; }
BitSet b = (BitSet)((LexerGrammar)grammar).charVocabulary.clone(); int[] elems = p.fset.toArray(); for (int j = 0; j < elems.length; j++) {
BitSet b = (BitSet)((LexerGrammar)grammar).charVocabulary.clone(); if (DEBUG_ANALYZER) System.out.println("charVocab is " + b.toString());