COP 4020 Midterm Langley

0.0(0)
Studied by 39 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/66

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 3:37 PM on 7/28/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

67 Terms

1
New cards

What is a defining characteristic of the functional programming style we discussed the first week of class? 

It tends to avoid or "shy away" from the traditional variable assignment paradigm.

2
New cards

Imperative languages like C, Ada, and Fortran can be described as belonging to the "von Neumann" family. What would this imply?

They are based on the variable assignment paradigm and are conceptually close to the hardware.

3
New cards

What is a practical benefit of studying different programming languages?

It helps you avoid the "when you only have a hammer, everything looks like a nail" problem in computer science.

4
New cards

What is a common characteristic of scripting languages like Perl, Python, and Ruby?

They usually have outstanding library capabilities and are suitable for one-off, lightweight programming tasks.

5
New cards

Syntax analysis (parsing) takes the stream of tokens from the lexer and organizes them into what kind of data structure?

A parse tree.

6
New cards

In the C compilation toolchain, using the gcc -E command would stop the process after which phase?

After the preprocessor has run.

7
New cards

The techniques developed for parsing programming languages have another common and practical application. What is it?

Parsing configuration files for applications.

8
New cards

Which of the following best lists the first three phases of a typical compiler?

Lexical Analysis (Scanning), Syntax Analysis (Parsing), and Semantic Analysis.

9
New cards

Besides the fact that we "learn better ways and evolve," what is another major reason mentioned for the existence of so many different programming languages?

The need for specialization in a particular problem space, such as TeX for typesetting or Perl for regular expressions.

10
New cards

What is a general, high-level distinction between a compiler and an interpreter?

Compilers transform source code into a new, directly executable form, while interpreters execute the source code more directly.

11
New cards

What is a key characteristic of the "stored program" paradigm in modern digital computers?

Data and instructions are fundamentally the same thing, represented as bits, and instructions can be treated as data.

12
New cards

A scanner (lexer) converts a stream of characters into a stream of tokens. What is a formal method often used to specify the patterns for these tokens?

Regular expression

13
New cards

Regular expressions are built from concatenation, alternation, and repetition. What additional mechanism do context-free grammars (CFGs) add?

Recursion

14
New cards

In the C family of languages, what are tokens like parentheses bizarrely called?

Punctuators

15
New cards

What are the two fundamental actions performed in bottom-up parsing?

Shift and Reduce

16
New cards

The "scanning" phase of compilation is described as fast and relatively easy. What is one of its most important functions besides identifying tokens?

Removing the "detritus of comments."

17
New cards

A parser's primary job is to act as a language "recognizer." According to the notes, parsing has generally been the arena for what formalism?

Context-Free Grammars (CFGs)

18
New cards

A grammar that can produce a string in more than one way (i.e., has more than one parse tree for a single sentence) is called:

Ambiguous

19
New cards

Scanner generators like flex often first create a non-deterministic finite automaton (NFA) from a specification. What is the next step such scanners then typically perform?

Convert the NFA to a Deterministic Finite Automaton (DFA).

20
New cards

Which style of parser is typically written by hand as a set of mutually recursive functions?

LL (Top-down)

21
New cards

Some languages, like older FORTRAN, had rigid line formatting rules. What modern languages are mentioned as caring about indentation for semantic meaning?

Python and Haskell

22
New cards

In the context of interpreters and interactive programming environments, what does the acronym REPL stand for?

Read-Evaluate-Print-Loop

23
New cards

In an LL-family parser, action routines can be embedded at arbitrary points of a production rule's right-hand side.

True

24
New cards

Most modern programming languages are free format.

Which of the following is not free format?

Python

25
New cards

A ______ is the shortest string of characters that have meaning in a language.

Token

26
New cards

What category of programming language is C?

Imperative language

27
New cards

An LR-family parser is a

Bottom-up

28
New cards

Consider the following Haskell session:

Prelude> let (+) a b = a - b
Prelude> 9 + 7
2

Certainly 9 + 7 does not usually equal 2. What’s going on here?

This is an instance of Haskell allowing the built-in “+” operator to be redefined.

29
New cards

What is the role of the lexical analyzer (or scanner) in a compiler?

To remove comments and identify tokens from the raw source code.

30
New cards

Which of the following are among Donald Knuth's arguments for the relevance of assembly/machine language, especially in regard to his multivolume work The Art of Computer Programming?

Modern high-level languages go in and out of fashion over relatively short periods of time.

High-level languages are often weak for expressing low-level machine-specific concerns.

Programmers tend to prefer constructions that are simplest in a given high-level language, rather than those that are best for the machine.

31
New cards

Why have projects like GCC and Clang moved from using parser generators (like Bison) to hand-written recursive-descent parsers?

For complex languages like C++, hand-written parsers can provide better error messages and are easier to debug and maintain.

32
New cards

A compiler that performs __________  of boolean expressions will generate
code that skips the second half of a computation when the overall value can be determined
from the first half alone.

short-circuit evaluation

33
New cards

In a language with ______ scoping, the binding of variable names can be determined at compile time by examining the text of the program, without consideration of the flow of control at run time.

static / lexical

34
New cards

Code Sample 1:

int f(int y);  // This is a forward declaration


x[f(z)] = x[f(z)] + 1;



Code Sample 2:

int f(int y); // This is a forward declaration


int s = x[f(z)]; 

x[s] = x[s] + 1;



Consider the above C code samples 1 and 2. Clearly both of these are subject to the array index possibly going out of bounds. However, the first code sample is liable to another possible problem that the second is not. What is the possible problem?

The function f() may not be pure, and may not necessarily return the same value each time it is called with the value "z".

35
New cards
tuple → "(" number " ," number ") "
number → one digit*
digit → zero | one
zero → "0"
one → "1"

Consider the above regular grammar. Terminals are indicated by quote marks (i.e., "0" indicates a literal zero); non-terminals begin with a lower-case letter. Of the following examples, which would be recognized as a tuple in the above regular grammar (please indicate all of the correct answers)?

(11,10001)

(1,1)

36
New cards

Orthogonality in a programming language refers to all of these characteristics except:

features must be linearly dependent.

37
New cards
<p><span>Which of the two answers fits better into the empty node above?</span></p>

Which of the two answers fits better into the empty node above?

Interpreter

38
New cards

In a context-free grammar, the symbols that appear on the left-hand side of a production rule are called what?

Non-terminals

39
New cards

Consider the following Haskell interactive session:

Prelude> let x = [1..]
Prelude> let y = [2..]
Prelude> x == y
False

Clearly, the interpreter has concluded that these two infinite lists are not the same. What mechanism in Haskell is used to perform this feat?

lazy evaluation

40
New cards

A type ________ occurs when a language silently converts a value of one type to a second
type when the second type is necessary in a particular context.

coercion

41
New cards

Which of the following contribute to the success of a programming language?

Being easy to learn. Having excellent compilers and/or interpreters. Patronage from a large economic entity, such as Microsoft's support for C#. Expressiveness and the ability to abstract at a useful level.

42
New cards

int x = 1;

int *y;

y = &x; // y points to x

x = 2; // x's value changes

printf("*y == %d\n", *y);

Consider the above C code block. When it is executed, it prints "*y == 2". This is an example of:

an alias

43
New cards

Consider the following code:

x = y - z;

a = x + z;

When can a compiler safely rewrite these two lines to:

x = y - z;

a = y;

If the compiler can guarantee that there are no issues with precision, overflow, underflow, or unrepresentable values (e.g., NaN).

44
New cards

What category of programming language is Scheme?

Functional, with some imperative characteristics.

45
New cards

When might the use of a linear jump table for a case/switch statement be a poor idea?

when the labels are non-dense, such as when you have a few labels spanning a very large range like 0 to 2^24.

46
New cards

Which of the following is not an iterative mechanism?

an "if" statement

47
New cards

The lexical scanner is responsible for discovering:

tokens

48
New cards

True or false: In a one-pass compiler, scanning, parsing, and semantic analysis are all interleaved.

True

49
New cards

If a programmer can pass a hint on to the compiler that a function is both not directly and indirectly recursive and thus can use static storage rather than allocating space for each activation with a separate activation record, this is an example of

a pragma

50
New cards

A programming language construct is said to have a ___________ if it influences subsequent computation in any way other than by returning a value for use in the surrounding context.

side effect

51
New cards

If a recursive routine in C declares a static variable, can that variable’s storage be allocated statically?

Yes, since the point of such a variable is to allow activations to share state

52
New cards

Consider this Haskell session:

Prelude> let min a b = if a < b then a else b

Prelude> min 9 11

9

Prelude> min 11 9

9

Prelude> min "xyz" "abc"

"abc"

Note that the function min is defined over all totally ordered types although there is no direct specification of this when we define min in the first line (the other lines just show what happens when you evaluate min against the pairs (9,11), (11,9), and ("xyz","abc")). This illustrates what concept in Haskell?

polymorphism

53
New cards

In C, a void * is

a universal reference type.

54
New cards

The languages Perl, Ruby, and Python all fall into

the scripting language family

55
New cards

Conventionally, what we would call the slash “/” in the following fragment of C?

int x = a / b;

operator

56
New cards

In Perl, consider the following code:

$x = "1" + 2

This is perfectly legitimate code, and will produce a value of 3 for $x. This is an example of:

coercion

57
New cards

Programs that fail to reclaim space for objects that are no longer needed are said to

"leak memory".

58
New cards

Identify what the following code fragment is:

((lambda (x) (* x x)) 3)

A lambda expression being evaluated against the number 3.

59
New cards

Arrays are ubiquitous in programming languages; among the common attributes of arrays are

discrete index types.

60
New cards

The idea of having exception handling as a part of the semantics of a programming language was motivated by three of the following; which one was not such a motivation?

Inability of single-pass compilers to find exceptions that have yet to be declared.

61
New cards

Lazy evaluation

is useful for expressing “infinite” data structures.

62
New cards

What is the function of the ellipsis (. . .) in the following C code?

int fail(char *format, ...) {

to allow a variable number of arguments for the function fail.

63
New cards

Pascal’s with statement was used to

declutter use of deeply nested records.

64
New cards

If a recursive routine declares an “own” or “static” variable, can that variable’s storage be allocated statically?

Yes

65
New cards

Records (also known as structures or structs) are used to

aggregate data.

66
New cards

What are reference counts used for?

garbage collection.

67
New cards

The above cartoon, "THE COMPILER BAR", illustrates which primary concept from our course material?

The sequential phases of a typical compiler, from lexical analysis to code generation.