本文整理了Java中org.antlr.runtime.BitSet
类的一些代码示例,展示了BitSet
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BitSet
类的具体详情如下:
包路径:org.antlr.runtime.BitSet
类名称:BitSet
[英]A stripped-down version of org.antlr.misc.BitSet that is just good enough to handle runtime requirements such as FOLLOW sets for automatic error recovery.
[中]一个精简版的org。antlr。杂项。足以处理运行时要求的位集,例如用于自动错误恢复的跟随集。
代码示例来源:origin: antlr/antlr3
protected BitSet combineFollows(boolean exact) {
int top = state._fsp;
BitSet followSet = new BitSet();
for (int i=top; i>=0; i--) {
BitSet localFollowSet = state.following[i];
/*
System.out.println("local follow depth "+i+"="+
localFollowSet.toString(getTokenNames())+")");
*/
followSet.orInPlace(localFollowSet);
if ( exact ) {
// can we see end of rule?
if ( localFollowSet.member(Token.EOR_TOKEN_TYPE) ) {
// Only leave EOR in set if at top (start rule); this lets
// us know if have to include follow(start rule); i.e., EOF
if ( i>0 ) {
followSet.remove(Token.EOR_TOKEN_TYPE);
}
}
else { // can't see end of rule, quit
break;
}
}
}
return followSet;
}
代码示例来源:origin: antlr/antlr3
public static BitSet of(int el) {
BitSet s = new BitSet(el + 1);
s.add(el);
return s;
}
代码示例来源:origin: antlr/antlr3
/** or this element into this set (grow as necessary to accommodate) */
public void add(int el) {
int n = wordNumber(el);
if (n >= bits.length) {
growToInclude(el);
}
bits[n] |= bitMask(el);
}
代码示例来源:origin: antlr/antlr3
/** return this | a in a new set */
public BitSet or(BitSet a) {
if ( a==null ) {
return this;
}
BitSet s = (BitSet)this.clone();
s.orInPlace(a);
return s;
}
代码示例来源:origin: antlr/antlr3
public boolean mismatchIsMissingToken(IntStream input, BitSet follow) {
if ( follow==null ) {
// we have no information about the follow; we can only consume
// a single token and hope for the best
return false;
}
// compute what can follow this grammar element reference
if ( follow.member(Token.EOR_TOKEN_TYPE) ) {
BitSet viableTokensFollowingThisRule = computeContextSensitiveRuleFOLLOW();
follow = follow.or(viableTokensFollowingThisRule);
if ( state._fsp>=0 ) { // remove EOR if we're not the start symbol
follow.remove(Token.EOR_TOKEN_TYPE);
}
}
// if current token is consistent with what could come after set
// then we know we're missing a token; error recovery is free to
// "insert" the missing token
//System.out.println("viable tokens="+follow.toString(getTokenNames()));
//System.out.println("LT(1)="+((TokenStream)input).LT(1));
// BitSet cannot handle negative numbers like -1 (EOF) so I leave EOR
// in follow set to indicate that the fall of the start symbol is
// in the set (EOF can follow).
if ( follow.member(input.LA(1)) || follow.member(Token.EOR_TOKEN_TYPE) ) {
//System.out.println("LT(1)=="+((TokenStream)input).LT(1)+" is consistent with what follows; inserting...");
return true;
}
return false;
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
public CommonTree getFirstDescendantWithType(org.antlr.runtime.BitSet types) {
if ( types.member(getType()) ) return this;
if ( children==null ) return null;
for (Object c : children) {
GrammarAST t = (GrammarAST)c;
if ( types.member(t.getType()) ) return t;
CommonTree d = t.getFirstDescendantWithType(types);
if ( d!=null ) return d;
}
return null;
}
代码示例来源:origin: antlr/antlr3
/**Is this contained within a? */
/*
public boolean subset(BitSet a) {
if (a == null || !(a instanceof BitSet)) return false;
return this.and(a).equals(this);
}
*/
public int[] toArray() {
int[] elems = new int[size()];
int en = 0;
for (int i = 0; i < (bits.length << LOG_BITS); i++) {
if (member(i)) {
elems[en++] = i;
}
}
return elems;
}
代码示例来源:origin: antlr/antlr3
public void remove(int el) {
int n = wordNumber(el);
if (n < bits.length) {
bits[n] &= ~bitMask(el);
}
}
代码示例来源:origin: antlr/antlr3
public List<? extends Token> getTokens(int start, int stop, int ttype) {
return getTokens(start,stop,BitSet.of(ttype));
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
/**
* Grows the set to a larger number of bits.
* @param bit element that must fit in set
*/
public void growToInclude(int bit) {
int newSize = Math.max(bits.length << 1, numWordsToHold(bit));
long newbits[] = new long[newSize];
System.arraycopy(bits, 0, newbits, 0, bits.length);
bits = newbits;
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
/** Construction from a list of integers */
public BitSet(List<Integer> items) {
this();
for (int i = 0; i < items.size(); i++) {
Integer v = items.get(i);
add(v);
}
}
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-analytics
public boolean mismatchIsMissingToken(IntStream input, BitSet follow) {
if ( follow==null ) {
// we have no information about the follow; we can only consume
// a single token and hope for the best
return false;
}
// compute what can follow this grammar element reference
if ( follow.member(Token.EOR_TOKEN_TYPE) ) {
BitSet viableTokensFollowingThisRule = computeContextSensitiveRuleFOLLOW();
follow = follow.or(viableTokensFollowingThisRule);
if ( state._fsp>=0 ) { // remove EOR if we're not the start symbol
follow.remove(Token.EOR_TOKEN_TYPE);
}
}
// if current token is consistent with what could come after set
// then we know we're missing a token; error recovery is free to
// "insert" the missing token
//System.out.println("viable tokens="+follow.toString(getTokenNames()));
//System.out.println("LT(1)="+((TokenStream)input).LT(1));
// BitSet cannot handle negative numbers like -1 (EOF) so I leave EOR
// in follow set to indicate that the fall of the start symbol is
// in the set (EOF can follow).
if ( follow.member(input.LA(1)) || follow.member(Token.EOR_TOKEN_TYPE) ) {
//System.out.println("LT(1)=="+((TokenStream)input).LT(1)+" is consistent with what follows; inserting...");
return true;
}
return false;
}
代码示例来源:origin: io.virtdata/virtdata-lib-realer
public CommonTree getFirstDescendantWithType(org.antlr.runtime.BitSet types) {
if ( types.member(getType()) ) return this;
if ( children==null ) return null;
for (Object c : children) {
GrammarAST t = (GrammarAST)c;
if ( types.member(t.getType()) ) return t;
CommonTree d = t.getFirstDescendantWithType(types);
if ( d!=null ) return d;
}
return null;
}
代码示例来源:origin: antlr/antlr3
/**Is this contained within a? */
/*
public boolean subset(BitSet a) {
if (a == null || !(a instanceof BitSet)) return false;
return this.and(a).equals(this);
}
*/
public int[] toArray() {
int[] elems = new int[size()];
int en = 0;
for (int i = 0; i < (bits.length << LOG_BITS); i++) {
if (member(i)) {
elems[en++] = i;
}
}
return elems;
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
public void remove(int el) {
int n = wordNumber(el);
if (n < bits.length) {
bits[n] &= ~bitMask(el);
}
}
代码示例来源:origin: antlr/antlr3
public List<? extends Token> getTokens(int start, int stop, int ttype) {
return getTokens(start,stop,BitSet.of(ttype));
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
/** return this | a in a new set */
public BitSet or(BitSet a) {
if ( a==null ) {
return this;
}
BitSet s = (BitSet)this.clone();
s.orInPlace(a);
return s;
}
代码示例来源:origin: antlr/antlr3
/**
* Grows the set to a larger number of bits.
* @param bit element that must fit in set
*/
public void growToInclude(int bit) {
int newSize = Math.max(bits.length << 1, numWordsToHold(bit));
long newbits[] = new long[newSize];
System.arraycopy(bits, 0, newbits, 0, bits.length);
bits = newbits;
}
代码示例来源:origin: antlr/antlr3
protected BitSet combineFollows(boolean exact) {
int top = state._fsp;
BitSet followSet = new BitSet();
for (int i=top; i>=0; i--) {
BitSet localFollowSet = state.following[i];
/*
System.out.println("local follow depth "+i+"="+
localFollowSet.toString(getTokenNames())+")");
*/
followSet.orInPlace(localFollowSet);
if ( exact ) {
// can we see end of rule?
if ( localFollowSet.member(Token.EOR_TOKEN_TYPE) ) {
// Only leave EOR in set if at top (start rule); this lets
// us know if have to include follow(start rule); i.e., EOF
if ( i>0 ) {
followSet.remove(Token.EOR_TOKEN_TYPE);
}
}
else { // can't see end of rule, quit
break;
}
}
}
return followSet;
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.antlr-runtime
public static BitSet of(int a, int b, int c) {
BitSet s = new BitSet();
s.add(a);
s.add(b);
s.add(c);
return s;
}
内容来源于网络,如有侵权,请联系作者删除!