lawrancej / CompilerKit

Compiler construction library in C.
GNU Lesser General Public License v2.1
55 stars 33 forks source link

Concatenation, Alternation, Kleene Star and Complement as flyweights #65

Open lawrancej opened 12 years ago

lawrancej commented 12 years ago

In preparation for doing derivative parsing, it'd be nice to make concatenation, alternation, kleene star, and complement a flyweights.

Empty Set and Empty String are already Singletons, meaning we don't need to allocate memory each time we ask for an instance. Symbol will soon be a flyweight, meaning we only allocate space when we ask for a unique character.

If the remaining regular expression classes (concatenation, alternation, kleene star and complement) are flyweights, it would mean that we only allocate space when we request a unique object. This may seem a bit excessive, but when doing derivative parsing, we generate a new regular expression each time we match a character. Allocating and deallocating space unnecessarily will slow things down.

This is an issue to take on with more than one person, and once derivative parsing is implemented, to verify things work properly.