There are a number of reasons why the analysis portion of a compiler is normally
separated into lexical analysis and parsing ( syntax analysis) phases.
- Simplicity of design is the most important consideration. The separation of lexical and syntactic analysis often allows us to simplify at least one of these tasks. For example, a parser that had to deal with comments and white space as syntactic units would be. Considerably more complex than one that can assume comments and white space have already been removed by the lexical analyzer. If we are designing a new language, separating lexical and syntactic concerns can lead to a cleaner overall language design.
- Compiler efficiency is improved. A separate lexical analyzer allows us to apply specialized techniques that serve only the lexical task, not the job of parsing. In addition, specialized buffering techniques for reading input characters can speed up the compiler significantly.
- Compiler portability is enhanced. Input-device-specific peculiarities can be restricted to the lexical analyzer.
resource___Compilers (2nd Edition)
written by-
Alfred V. Abo
Columbia University
Monica S. Lam
Stanford University
Ravi Sethi
Avaya
Jeffrey D. Ullman
Stanford University