This post has my answers for "Check Your Understanding" questions in section 1.5, Chapter 1 of the book Programming Language Pragmatics by Michael L. Scott.
Chapter 1, Section 1.5 - Check Your Understanding
Question # 11. Explain the distinction between interpretation and compilation. What are the comparative advantages and disadvantages of the two approaches?
Compiler produces machine code from high-level language. After the compilation, the machine code can be directly run on the target system which is locus during runtime. The machine code produced on one architecture cannot be run on a machine with different architecture. The compiled program is faster than its interpreter counterpart.
The interpreter is usually the locus when the program is running. The program written in high-level language is directly run on the target machine through interpreter. In a sense, the high-level code is machine instruction for interpreter. Most of the interpreter are slower in execution as most of the decisions during the course of the program are deferred until the control reaches to the particular statement. However the debugging is much more easier to do in interpreter as interpreter has control throughout the execution of the program. Moreover the interpreter can do useful features like on-the-fly compilation so that the program can generate code during execution which is again consumed/executed by interpreter.
Question #12. Is Java compiled or interpreted (or both)? How do you know?
Java is both compiled and interpreted. Java compiler transforms Java source code to bytecode. Java Virtual Machine (interpreter) executes bytecode.
Question #13. What is the difference between a compiler and a pre-processor?
Pre-processor is needed step before compilation. Compilation transforms the code substantially but pro-processing is usually is light-weight such as removing comments, replacing macros etc.
Question #14. What was the intermediate form employed by the original AT&T C++ compiler?
The intermediate form produced by AT & T C++ compiler is "C".
Questions #15. What is P-code?
Question #16. What is bootstrapping?
Typically the programming language compiler is written by itself meaning that a C compiler is usually written using C. However at first there will not be any compiler to compile the code written in C. Usually a tiny interpreter is written in a different language to produce machine instruction (tiny compiler). Later the tiny compiler produced by interpreter is used to compile the compiler. This is called bootstrapping. In similar fashion more features are added incrementally to produce high quality compiler.
Question #17. What is a just-in-time compiler?
Just-in-time compiler is a feature of interpretor that converts byte-codes to machine instruction while the program is under execution. This is done mainly to increase performance (speed of execution)
Question #18. Name two languages in which a program can write new pieces of itself "on the fly"
List and Prolog (Python, Perl, TCL also have similar features)
Question #19. Briefly describe three "unconventional" compilers - compilers whose purpose is not to prepare a high-level program for execution on a microprocessor
- SQL - Translates statements to operations on database
- Compilers to translate logic-level circuit specification into photographic masks for computer chips
- TEX that translates document to commands for printers
Question #20. List six kinds of tools that commonly support the work of a compiler within a larger programming environment
- Style Checkers
- Configuration Management
Question #21. Explain how IDEs differs from a collection of command-line tools
All the tools are integrated in an environment often collaborates amongst themselves where as the command line tools are used merely in isolation. For example when a program crashes, IDE points which line of the code is causing the issue and pops up the code in the editor. The developer can make the change and save the file. IDE automatically builds it.