2

Even though grammars can do what regular expressions do, why are regular expression employed instead of grammars in lexical analysis?

Yuval Filmus
  • 280,205
  • 27
  • 317
  • 514
ataush
  • 23
  • 3

1 Answers1

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