Chapter 3 review. Are the following statements true or false? Explain why or why not.
a) High-level programming languages help people focus on different kinds of
problems.
True. While low-level languages, such as assembly languages, tend to force programmers
to focus on how the machine works, high-level languages, such as Java, C++,
LISP, etc., let developers think more in terms of the problems they want to
solve.
b) Both syntax diagrams and BNF rules have non-terminals as well as tokens,
but they look different.
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.
c) Pascal and C express assignment differently, but either way they modify
the value of a variable.
True. In Pascal, the assignment operator is :=, while in C it is =, but they
accomplish the same thing: modifying the lvalue or value of the variable to
the left of the operator with the value produced by the expression to the right
of the operator.
d) Using the double type guarantees
that floating point computations will have no errors.
False. Round-off error may occur due to the finite number of bits that double
uses represent real (or irrational) numbers, which require an infinite number
of places.
e) In C-style languages, functions always return a value.
False. C-style languages allow for functions with a void
return type, which do not return a value. Other languages, such as Pascal, distinguish
between functions, which must return a value, and procedures, which cannot.
f) Assembly language associates symbols with numeric codes for an actual machine.
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.
g) 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.
i) 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.
k) Interpreted languages with reusable resources in libraries facilitate rapid
prototyping of software.
True. When a virtual machine provides resources such as user interface components
and common data structures, developers can easily and rapidly create prototypes
or early versions of software for their customers.
m) Compiled code runs faster than a speeding bullet, or at least equivalent
interpreted code.
True. Compiled code runs directly on an actual machine, avoiding the overhead
of a virtual machine during execution.
n) 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.
o) 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 not a hard and fast rule, however. Java combines the best of both
worlds by compiling to a virtual machine code, then the Java Virtual Machine
interprets this code. Both Java compiler and virtual machine interpreter perform
strong type checking, in order to facilitate portability and security of code
running over the Internet.
p) 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.
q) Preprocessor directives perform type checking early.
False. Preprocessor directives occur early, but know nothing about types.
r) 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.
s) 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.
t) 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.
u) A Java compiler translates source code into actual machine code.
False. A Java compiler will translate source code into "byte code", which
executes on the Java virtual machine.
v) 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).
w) 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.
x) 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.
y) 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).
z) 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 Java. Believe it or not, the
grammar of English is far more complex than that of Java!