regular expression parser and automata constructor