State machines can be used in a scanner and a parser for program
compilation. The state machines can be non-table-driven, but rather are
encoded directly in bytecodes. A special algorithm can be used to
generate the multi-way branch associated with a state in a state machine
so that the multi-way branch meets specified optimality requirements on
the size of the bytecodes. The bytecodes so implemented can be more
compact and run faster than those generated un-optimized. The algorithm
for obtaining an optimal implementation of the multi-way branch can be
conceptually divided into three phases: first, it constructs a set of
subarrays that form a disjoint covering for the target array; second, it
determines an optimal branch implementation for each subarray; and third,
it determines the optimal branch implementation for each union of one or
more adjacent subarrays, culminating to the optimal implementation for
the entire target array. This description is not intended to be a
complete description of, or limit the scope of, the invention. Other
features, aspects, and objects of the invention can be obtained from a
review of the specification, the figures, and the claims.