|
|
12.2.1 Scanning
For most languages---FORTRAN is a vivid exception---scanning is simple and requires little to no backtracking. Regular expressions can be designed and a tool used, or even better (say most compiler designers), a scanner itself can be written rather than generated. It has proved to be a better method than table-driven techniques. For FORTRAN, it may facilitate things to reuse a scanner from another system or even to buy one.
It is also best to keep the scanner simple, letting later phases do more work. This applies, in particular, to symbol table creation. A (hashed!) name table may be created during scanning, but the true symbol table is best created during semantic analysis, when names may be resolved. For example, Ada array references have the same syntax as function calls and can be distinguished only after declarations have been processed.
Lexical analysis is a good example of software that can be fine-tuned by writing some of the routines in assembler.
|