- Write a clearly legible T to the left of each of the
following that is true, and a clearly legible F to the left
of each that is false.
- All compilers translate to machine language.
F
- All programming language implementations are compilers.
F
- A simple value is a value that has no visible internal
structure.
T
- Integers are typically considered complex values.
F
- A data structure that changes over time is not
considered to be a value.
T
- A token can only have one associated lexeme.
F
- A variable name is typically a single lexeme in a program.
T
- Backus-Naur Form is a notation for giving precise definitions
of syntax.
T
- Pattern matching can be used to bind names by solving
simple equations.
T
- In C++, every block begins at the start of a function,
and ends at the end of the function.
F
- An implementation of a programming language is not
an adequate definition of the language. Why not? What
would be the consequences of using an implementation as a
definition?
Possible consequences:
- The definition is very difficult to understand.
- If there is a bug in the implementation, it cannot be fixed.
- It is impossible to have partially defined features, such
as an undefined order of evaluation of certain expressions.
- What is an important advantage of the linked representation
of sequences over the sequential representation?
It is easy to extend sequences by adding values to the start.
Also, the linked representation permits structure sharing,
which sometimes greatly reduces memory requirements.
There are other advantages, such as the ability to add values
into the middle of the sequence.
- What is an important advantage of the sequential representation
of sequences over the linked representation?
Random access and reduced memory requirements for individual
lists are important advantages.
- What is shadowing, and how can it occur? Give an example.
Shadowing occurs when a binding of an identifier hides another
binding of the same identifier that would have been visible
but for this new binding. It occurs when a binding is done
in an inner scope. For example, in C++,
{int x;
...
{int x;
...
}
}
the binding of x (to a variable) in the inner block hides the
binding of x (to a different variable) in the outer block.
- Show that the following BNF grammar is ambiguous.
The start symbol is <S>.
<S> ::= <S> a
| a <S>
| a
It suffices to show two different parse trees for string aa.
Here they are.
S S
/ \ / \
S a a S
| |
a a
- Show a parse tree for string
aacacab
according to
the following grammar, where the start symbol is <S>.
<S> ::= <F> a <S>
| b
<F> ::= a <F>
| c
S
/|\
/ | \
/ | \
/ | \
/ | \
/ | \
/ | \
F a S
/ \ /|\
a F / | \
/ \ F a S
a F | |
| c b
c