2. Explain the three reasons why lexical analysis is separated from syntax analysis.
– Simplicity—Techniques for lexical analysis are less complex than those
required for syntax analysis, so the lexical-analysis process can be sim-pler if it is separate. Also, removing the low-level details of lexical analy-sis from the syntax analyzer makes the syntax analyzer both smaller and
less complex.
– Efficiency—Although it pays to optimize the lexical analyzer, because
lexical analysis requires a significant portion of total compilation time,
it is not fruitful to optimize the syntax analyzer. Separation facilitates
this selective optimization.
– Portability—Because the lexical analyzer reads input program files
and often includes buffering of that input, it is somewhat platform
dependent. However, the syntax analyzer can be platform independent.
It is always good to isolate machine-dependent parts of any software
system.