Chapter 4 review. Are the following statements true or false? Explain why or why not.

a) Compiled code runs faster than a speeding bullet, or at least equivalent interpreted code.
True. Compiled code runs directly runs directly on an actual machine, avoiding the overhead of a virtual machine during execution.

b) Compilers provide better support for rapid prototyping of experimental software.
False.  Generally, interpreters are better for rapid prototyping, because translation time to a virtual machine is faster.  So programmers can see the results of a program more quickly.  On the other hand, compilers produce faster production code.

c) Interpreters usually provide stronger type checking to make sure source code is correct.
False.  Type checking is more necessary and common for compiled languages, since type-checking at run-time is not possible on most actual machines.  This is a hard and fast rule, however.  Java is an example of an interpreted languages that performs strong type checking, in order to facilitate portability and security of code running over the Internet.

d) An advantage of compilers is that they perform more checks on code at run-time.
False.  Compiler usually perform more checks all right, but at translation (compile) time, not run-time.

e) Preprocessor directives perform type checking early.
False.  Preprocessor directives occur early, but know nothing about types.

f) A compiler generates nearly executable machine code, nearly since it won’t quite execute as is.
True.  A compilation succeeds, a C++ compiler produces an object code file from each source code file.  The linker must then combine object code files, for example, a program's object code with object code from a library, such as iostream code, to produce an executable program.

g) A linker combines information in header files with object code.
False.  Linkers combine object code files, not header files.  Header files contain source code information.  For example, iostream.h contains the declarations for cout, cin, endl, etc., in C++.  A vendor-supplied object code library contains the definitions for these objects in machine code.

h) A loader has to adjust any machine addresses in a program’s machine code.
True.  The linker produces machine code with relative addresses.  The loader determines where to load the code (so that more than one program can be loaded into memory) and binds the relative addresses to absolute addresses recognizable by the actual machine.

i) The Lookout program analyzer is another preprocessor.
True.  It processes C++ code as a step before any of the usual steps of compiling a program.

j) Knobby’s World is a virtual machine—can’t see him, but he’s there!
True. The virtual machine executes the primitive instructions, such as move, left and read.  The Knobby's World interpreter translates programs into code for this virtual machine, a byte code.

k) The Knobby’s World interpreter translates instructions into byte code, a form of actual machine code.
False.  The byte code is not the code of an actual machine (such as a Pentium), but a virtual machine (part of the software of the Knobby's World program).

l) Translation to byte code is part of the reason for the success of the Java language on the Internet.
True.  Since virtual machines for Java byte code have been implemented for most major platforms, Java programs are very portable, i.e., they will run on just about any machine connected to the Internet.

m) A scanner (or tokenizer) recognizes keywords, identifiers, numbers and subway tokens.
False.  Forget the subway tokens.  A scanner recognizes all legal tokens as defined for a particular programming language.

n) A free format language simply ignores all space characters (including tabs and newlines).
False.  A free format language ignores any extra space characters.  The first space may be a separator; i.e., int x is two tokens (a type followed by an identifier), while intx is just one (an identifier).

o) A parser analyzes syntactic structures of a language, according to the grammar of English.
False.  That's what it does all right, but according to the grammar of a particular programming language, such as C++.  Believe it or not, the grammar of English is far more complex than that of C++!

p) Both syntax rules and syntax diagrams have non-terminals as well as tokens.
True. In rules, non-terminals are expanded by other rules; in diagrams, non-terminals are expanded by other diagrams.  Different notations, same power: anything that can be expressed by diagrams can be expressed by rules.

q) A formal semantics specifies the meaning of a program in terms of machine code.
False.  A formal semantics specifies meaning in a notation independent of machine code, so one can make sure the machine does what it's supposed to do.

r) Assembly language associates symbols with a numeric actual machine code.
True.  Assembly language has instructions, such as STO and LD, which correspond one-for-one with actual machine instructions, and other symbols, such as X, which correspond to numeric addresses in memory.

s) If you like "spaghetti," maybe you’ll like GOTOs?
True.  GOTO statements can lead to "spaghetti" programs, in which the dynamic (run-time) behavior of the program bears little resemblance to the static (source code) structure of the program.  Following the execution is like following a strand of spaghetti in a bowl.

t) FORTRAN and COBOL, two of the oldest high level languages, are still widely used because of the elegance of their design.
False.  They may or may not have seemed elegant when they were originally designed (and since redesigned many times), but by modern standards, these languages are rather ungainly.  FORTRAN is still tied to the format of punched cards and COBOL is verbose.   They are still widely used largely because there are large amounts of code developed and maintained already written in these languages.

u) Structured programming avoids GOTOs by promoting functional decomposition.
False.  The key to avoiding GOTOs is providing control structures, such as if-then-else and while loops and exceptions, that make GOTOs unnecessary.  Functional decomposition, while often associated with structured programming, is really a separate design methodology, which can be used for designing programs in any language that supports functions or subprograms.

v) Pascal and C were both designed as instructional languages.
False.  Pascal was, and became widely popular in universities, but C was designed as a systems programming language, facilitating the relatively portable implementation of the Unix operating system.

w) C++ is a hybrid language, combining the systems programming features of C and the business processing strengths of COBOL.
False.  C++ inherits little from COBOL (and is not likely to supplant COBOL in business processing applications either).  But it is a hybrid language, adding to C object-oriented features found in Simula and Smalltalk.

x) Functional and logic programming both try to break free of a bottleneck in the dominant von Neumann machine architecture.
True.  Whereas imperative languages such as FORTRAN, Pascal or C emphasize sequential control structures (which boil down to instructions passing through the program address register) and assignment (which boils down to data transferring from memory to data registers and back), these new programming paradigms set up the possibility of reduce the dependency on sequential control and assignment, thus facilitating the use of many processors executing parts of a program in parallel.