Even though grammars can do what regular expressions do, why are regular expression employed instead of grammars in lexical analysis?
Asked
Active
Viewed 191 times
1 Answers
2
Regular languages are faster to recognize, and so they are preferred whenever possible. Fortunately, regular expressions are usually good enough for describing the lexemes of a language.
Indeed, in some sense the separation between lexical analysis and parsing is exactly due to this fact, that lexical analysis can be done more efficiently than parsing.
Yuval Filmus
- 280,205
- 27
- 317
- 514