Question: What is the pass of compiler? Explain how the single and multi- pass compilers work? What is the effect of reducing the number of passes?
- One complete scan of a source program is called pass.
- Pass include reading an input file and writing to the output file.
- In a single pass compiler analysis of source statement is immediately followed by synthesis of equivalent target statement.
- It is difficult to compile the source program into single pass due to:
- Forward reference: a forward reference of a program entity is a reference to the entity which precedes its definition in the program.
- This problem can be solved by postponing the generation of target code until more information concerning the entity becomes available.
- It leads to multi pass model of compilation.
- In Pass I: Perform analysis of the source program and note relevant information.
- In Pass II: Generate target code using information noted in pass I.
- It is desirable to have a few passes, because it takes time to read and write intermediate file.
- On the other hand if we group several phases into one pass we may be forced to keep the entire program in the memory. Therefore memory requirement may be large.