本文整理汇总了Java中antlr.collections.impl.BitSet类的典型用法代码示例。如果您正苦于以下问题:Java BitSet类的具体用法?Java BitSet怎么用?Java BitSet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BitSet类属于antlr.collections.impl包,在下文中一共展示了BitSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: removeCompetingPredictionSets
import antlr.collections.impl.BitSet; //导入依赖的package包/类
/** Remove the prediction sets from preceding alternatives
* and follow set, but *only* if this element is the first element
* of the alternative. The class members currenBlock and
* currentBlock.analysisAlt must be set correctly.
* @param b The prediction bitset to be modified
* @el The element of interest
*/
private void removeCompetingPredictionSets(BitSet b, AlternativeElement el) {
// Only do this if the element is the first element of the alt,
// because we are making an implicit assumption that k==1.
GrammarElement head = currentBlock.getAlternativeAt(currentBlock.analysisAlt).head;
// if element is #(. blah) then check to see if el is root
if (head instanceof TreeElement) {
if (((TreeElement)head).root != el) {
return;
}
}
else if (el != head) {
return;
}
for (int i = 0; i < currentBlock.analysisAlt; i++) {
AlternativeElement e = currentBlock.getAlternativeAt(i).head;
b.subtractInPlace(e.look(1).fset);
}
}
示例2: genBitsetsHeader
import antlr.collections.impl.BitSet; //导入依赖的package包/类
protected void genBitsetsHeader(
Vector bitsetList,
int maxVocabulary
) {
println("");
for (int i = 0; i < bitsetList.size(); i++)
{
BitSet p = (BitSet)bitsetList.elementAt(i);
// Ensure that generated BitSet is large enough for vocabulary
p.growToInclude(maxVocabulary);
// initialization data
println("static const unsigned long " + getBitsetName(i) + "_data_" + "[];");
// BitSet object
println("static const "+namespaceAntlr+"BitSet " + getBitsetName(i) + ";");
}
}
示例3: getLookaheadTestExpression
import antlr.collections.impl.BitSet; //导入依赖的package包/类
protected String getLookaheadTestExpression(Lookahead[] look, int k) {
StringBuffer e = new StringBuffer(100);
boolean first = true;
e.append("(");
for (int i = 1; i <= k; i++) {
BitSet p = look[i].fset;
if (!first) {
e.append(") && (");
}
first = false;
// Syn preds can yield <end-of-syn-pred> (epsilon) lookahead.
// There is no way to predict what that token would be. Just
// allow anything instead.
if (look[i].containsEpsilon()) {
e.append("true");
} else {
e.append(getLookaheadTestTerm(i, p));
}
}
e.append(")");
return e.toString();
}
示例4: clone
import antlr.collections.impl.BitSet; //导入依赖的package包/类
/** 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;
}
示例5: getLookaheadTestExpression
import antlr.collections.impl.BitSet; //导入依赖的package包/类
protected String getLookaheadTestExpression(Lookahead[] look, int k) {
StringBuffer e = new StringBuffer(100);
boolean first = true;
e.append("(");
for (int i = 1; i <= k; i++) {
BitSet p = look[i].fset;
if (!first) {
e.append(") && (");
}
first = false;
// Syn preds can yield <end-of-syn-pred> (epsilon) lookahead.
// There is no way to predict what that token would be. Just
// allow anything instead.
if (look[i].containsEpsilon()) {
e.append("true");
}
else {
e.append(getLookaheadTestTerm(i, p));
}
}
e.append(")");
return e.toString();
}
示例6: match
import antlr.collections.impl.BitSet; //导入依赖的package包/类
/**Make sure current lookahead symbol matches the given set
* Throw an exception upon mismatch, which is catch by either the
* error handler or by the syntactic predicate.
*/
public void match(BitSet b) throws MismatchedTokenException, TokenStreamException {
String text = LT(1).getText();
int la_1 = LA(1);
try {
super.match(b);
parserEventSupport.fireMatch(la_1,b, text, inputState.guessing);
}
catch (MismatchedTokenException e) {
if (inputState.guessing == 0)
parserEventSupport.fireMismatch(la_1, b, text, inputState.guessing);
throw e;
}
}
示例7: match
import antlr.collections.impl.BitSet; //导入依赖的package包/类
public void match(BitSet b) throws MismatchedCharException, CharStreamException {
if (!b.member(LA(1))) {
throw new MismatchedCharException(LA(1), b, false, this);
}
else {
consume();
}
}
示例8: checkForInvalidArguments
import antlr.collections.impl.BitSet; //导入依赖的package包/类
protected void checkForInvalidArguments(String[] args, BitSet cmdLineArgValid) {
// check for invalid command line args
for (int a = 0; a < args.length; a++) {
if (!cmdLineArgValid.member(a)) {
warning("invalid command-line argument: " + args[a] + "; ignored");
}
}
}
示例9: MismatchedCharException
import antlr.collections.impl.BitSet; //导入依赖的package包/类
public MismatchedCharException(char c, BitSet set_, boolean matchNot, CharScanner scanner_) {
super("Mismatched char", scanner_.getFilename(), scanner_.getLine(), scanner_.getColumn());
mismatchType = matchNot ? NOT_SET : SET;
foundChar = c;
set = set_;
scanner = scanner_;
}
示例10: look
import antlr.collections.impl.BitSet; //导入依赖的package包/类
/**Combine the lookahead computed for each alternative */
public Lookahead look(int k, AlternativeBlock blk) {
if (DEBUG_ANALYZER) System.out.println("lookAltBlk(" + k + "," + blk + ")");
AlternativeBlock saveCurrentBlock = currentBlock;
currentBlock = blk;
Lookahead p = new Lookahead();
for (int i = 0; i < blk.alternatives.size(); i++) {
if (DEBUG_ANALYZER) System.out.println("alt " + i + " of " + blk);
// must set analysis alt
currentBlock.analysisAlt = i;
Alternative alt = blk.getAlternativeAt(i);
AlternativeElement elem = alt.head;
if (DEBUG_ANALYZER) {
if (alt.head == alt.tail) {
System.out.println("alt " + i + " is empty");
}
}
Lookahead q = elem.look(k);
p.combineWith(q);
}
if (k == 1 && blk.not && subruleCanBeInverted(blk, lexicalAnalysis)) {
// Invert the lookahead set
if (lexicalAnalysis) {
BitSet b = (BitSet)((LexerGrammar)grammar).charVocabulary.clone();
int[] elems = p.fset.toArray();
for (int j = 0; j < elems.length; j++) {
b.remove(elems[j]);
}
p.fset = b;
}
else {
p.fset.notInPlace(Token.MIN_USER_TYPE, grammar.tokenManager.maxTokenType());
}
}
currentBlock = saveCurrentBlock;
return p;
}
示例11: lookaheadEquivForApproxAndFullAnalysis
import antlr.collections.impl.BitSet; //导入依赖的package包/类
/** If the first k-1 sets are singleton sets, the appoximate
* lookahead analysis is equivalent to full lookahead analysis.
*/
public static boolean lookaheadEquivForApproxAndFullAnalysis(Lookahead[] bset, int k) {
// first k-1 sets degree 1?
for (int i = 1; i <= k - 1; i++) {
BitSet look = bset[i].fset;
if (look.degree() > 1) {
return false;
}
}
return true;
}
示例12: genCases
import antlr.collections.impl.BitSet; //导入依赖的package包/类
/** Generate a series of case statements that implement a BitSet test.
* @param p The Bitset for which cases are to be generated
*/
protected void genCases(BitSet p) {
if ( DEBUG_CODE_GENERATOR ) System.out.println("genCases("+p+")");
int[] elems;
elems = p.toArray();
// Wrap cases four-per-line for lexer, one-per-line for parser
int wrap = 1; //(grammar instanceof LexerGrammar) ? 4 : 1;
int j=1;
boolean startOfLine = true;
for (int i = 0; i < elems.length; i++) {
if (j==1) {
print("");
} else {
_print(" ");
}
_print("case " + getValueString(elems[i]) + ":");
if (j==wrap) {
_println("");
startOfLine = true;
j=1;
}
else {
j++;
startOfLine = false;
}
}
if (!startOfLine) {
_println("");
}
}
示例13: getLookaheadTestTerm
import antlr.collections.impl.BitSet; //导入依赖的package包/类
/**Generate a depth==1 lookahead test expression given the BitSet.
* This may be one of:
* 1) a series of 'x==X||' tests
* 2) a range test using >= && <= where possible,
* 3) a bitset membership test for complex comparisons
* @param k The lookahead level
* @param p The lookahead set for level k
*/
protected String getLookaheadTestTerm(int k, BitSet p) {
// Determine the name of the item to be compared
String ts = lookaheadString(k);
// Generate a range expression if possible
int[] elems = p.toArray();
if (elementsAreRange(elems)) {
return getRangeExpression(k, elems);
}
// Generate a bitset membership test if possible
StringBuffer e;
int degree = p.degree();
if ( degree == 0 ) {
return "true";
}
if (degree >= bitsetTestThreshold) {
int bitsetIdx = markBitsetForGen(p);
return getBitsetName(bitsetIdx) + ".member(" + ts + ")";
}
// Otherwise, generate the long-winded series of "x==X||" tests
e = new StringBuffer();
for (int i = 0; i < elems.length; i++) {
// Get the compared-to item (token or character value)
String cs = getValueString(elems[i]);
// Generate the element comparison
if( i > 0 ) e.append(" || ");
e.append(ts);
e.append(" == ");
e.append(cs);
}
return e.toString();
}
示例14: lookaheadIsEmpty
import antlr.collections.impl.BitSet; //导入依赖的package包/类
/**Is the lookahead for this alt empty? */
protected boolean lookaheadIsEmpty(Alternative alt, int maxDepth) {
int depth = alt.lookaheadDepth;
if ( depth == GrammarAnalyzer.NONDETERMINISTIC ) {
depth = grammar.maxk;
}
for (int i=1; i<=depth && i<=maxDepth; i++) {
BitSet p = alt.cache[i].fset;
if (p.degree() != 0) {
return false;
}
}
return true;
}
示例15: match
import antlr.collections.impl.BitSet; //导入依赖的package包/类
/**Make sure current lookahead symbol matches the given set
* Throw an exception upon mismatch, which is catch by either the
* error handler or by the syntactic predicate.
*/
public void match(BitSet b) throws MismatchedTokenException, TokenStreamException {
if (!b.member(LA(1)))
throw new MismatchedTokenException(tokenNames, LT(1), b, false, getFilename());
else
// mark token as consumed -- fetch next token deferred until LA/LT
consume();
}