[antlr-interest] Re: ANTLR Java Code Generation

Robert Colquhoun rjc at trump.net.au
Wed Nov 14 00:06:46 PST 2001


Hi,

Attached is a BitSet class that uses offset's to work better with sparse 
sets that i did a few months ago.

Have kind of been busy in the meantime and not had the chance to try and 
integrate it into antlr.

To use you would do something like this:

private static final BitSet _tokenSet_0 = getTokenSet0();
private static final BitSet getTokenSet0() {
	long [] data = {
		-549755813896L,
		-268435457L
	};
	int offset = 0;
	return getTokenSet(data, offset);
}
//the routine below should be put into the parent class
private static final BitSet getTokenSet(long[] data, int offset) {
	BitSet bt = new Bitset();
	for (int i = 0; i < data.length; i++) {
		long val = data[i];
		for (int j = 0; j < 64; j++) bt.add((val & (1 << j)) + offset);
	}
}

Looks kind of icky at first but does get rid of all the trailing 0's by 
increasing the offset appropriately.  With the above the standard 
java.util.BitSet can be freely substituted.

(The -1 case is a bit more difficult, can brute force this by force setting 
to 1 all values between 0 and offset in a loop, but a better solution is to 
have some sortof negate flag if the value is within range...need to think 
about this some more).

- Robert

Things to note about attached file
	- included is obligatory eratosthenes sieve test,type 'make test' first is 
antlr current bitset, 2nd is bitset i just did in java, 3rd is standard 
java.util.BitSet class finally C++ version of my bitset class
	- the 3 java cases run about the same speed for the above test, the c++ 
case is about 3x faster(on slow hpux jvm).
	- C++ source is functional but looks like a java ported program, needs 
some cleaning up
	- the distinguishing feature for the bitset i did was to try and work well 
for sparse sets ie when you are only looking for a couple of characters in 
the whole unicode set - the sieve test does not show behavior in this 
situation, need another test.
	- the Makefile only sortof works. sorry.

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: bitset.tar.gz
Type: application/octet-stream
Size: 5348 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20011114/3a5299fe/bitset.tar.obj


More information about the antlr-interest mailing list