places where sets are useful

Marty Sasaki sasaki at harvard.ARPA
Wed Mar 6 14:09:30 AEST 1985


I use sets in two places, in recursive decent parsers, and in my chess
playing program. If sets were implemented in C, then certain
optimizations could be done by the compiler. Of couse, both places
require more bits than provided in a long, but both of the Pascal
compilers that I use allow at least 64 items in a set (DEC's Pascal for
VMS, and Oregon Software's compiler for PDP-11's).

The chess program represents chess boards as a set of 64 squares. By
doing set operations on these "bitboards" one can generate moves, check
for attacking pieces, evaluate pawn structure, etc. These operations can
be done very fast.

The recursive decent parser uses sets for error recovery. When a
procedure which deals with a non-terminal is called, it is passed the
set of symbols in the follow set for the non-terminal. If an error
occurs, symbols are skipped until a symbol in the input stream is found
that is in the follow set. The procedure is then returns.
-- 
			Marty Sasaki
			Havard University Science Center
			sasaki at harvard.{arpa,uucp}
			617-495-1270



More information about the Comp.lang.c mailing list