I'm a bit confused about the concept of finite state automata (FSA) and regular expression (RE) in lexical analysis. I have reading some books about compiler construction. At the part of tokenization, all the books I read talk about the regular expression first to recognize the tokens. For example, the regex below is to recognize the
([a-zA -Z] | _ | $ )([a-zA -Z0 -9] | _ | $)*
Then, they jumped to explain another technique which is finite state automata (FSA). As a result, some questions have come to my mind which are:
1- What part I should learn first? RE or FSA?.
2- Programmatically, which part should be converted to other to build the lexer? RE ==> FSA or FSA to RE.
3-Since all tokens can be recognized by regular expression, then, why we need finite state automata?.
Sorry for the to many questions, but I really can't figure out how to start. many thanks in advance.