constructed dfa & refactored ast functions