# Do we need regular expression first or finite state automata in lexical anlysing? [closed]

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 identifier:

([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.

• @Stephen, to be more specific, let say i want to write a program to recognize identifier and digit tokens. What should I do first? drawing the FSA then convert it to RE or the opposite? – FSm Nov 27 '17 at 19:54