Chapter 7 Flashcards

(37 cards)

1
Q

What is semantics?

A

The meaning of programs; how the language constructs actually behave when executed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the purpose of semantic analysis?

A

To check whether the program makes sense beyond syntax—types, declarations, scopes, returns, etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is static semantics?

A

Rules checked at compile time (types, variable declarations, scope, returns, etc.).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is dynamic semantics?

A

The meaning of program execution—what happens when the program runs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a semantic error?

A

A program that is syntactically correct but makes no sense (e.g., adding a number to a string).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a data type?

A

A category of values (int, float, bool) defining what operations are allowed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is type checking?

A

The compiler verifies expressions use types correctly (e.g., cannot add a bool to a string).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is strong typing?

A

A language that prevents mixing incompatible types—errors are caught early.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is weak typing?

A

A language that allows more type conversions, sometimes unsafely.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is type inference?

A

The compiler figures out the type for you automatically, without explicit type declarations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a coercion?

A

An automatic type conversion performed by the compiler (e.g., int → float).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a cast?

A

A manual type conversion written by the programmer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is scope?

A

The region of a program where a variable or identifier is visible and accessible.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is static (lexical) scoping?

A

The scope of a variable is determined by where it appears in the source code,
❌ NOT by the order in which functions are called at runtime.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is dynamic scoping?

A

A variable’s scope depends on the calling sequence at runtime.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a binding?

A

An association between a name and something else (type, value, location).

17
Q

What is a binding time?

A

The time when a binding is created (compile time, run time, link time, etc.).

18
Q

What is a declaration?

A

A statement that introduces a name and often its type.

19
Q

What is a definition?

A

A declaration that also allocates storage or provides a value.

20
Q

What is a symbol table?

A

A structure the compiler uses to track identifiers, their types, scope, and bindings.

21
Q

What is an L-value?

A

variable on the left side
stands for a location

22
Q

What is an r-value?

A

A value produced by an expression (the right side of an assignment).

23
Q

What is an l-value vs r-value example?

A

In x = y + 2, x is an l-value (location), y+2 is an r-value (value).

24
Q

What is a side effect?

A

An action besides returning a value (e.g., modifying a variable or printing).

25
What is referential transparency?
An expression can be replaced by its value with no change in program behavior—important in functional languages.
26
What is a semantic rule?
A rule that defines how syntactic constructs behave or how they should be checked.
27
What is a type system?
A set of rules describing how types work and how they interact in a language.
28
What is a type error?
Using an operation with the wrong type (e.g., `“hello” - 3`).
29
What is short-circuit evaluation?
Logical operators stop evaluating as soon as the result is known (e.g., false && anything).
30
What is a runtime semantic check?
Errors checked while the program runs (e.g., divide-by-zero).
31
What does 'context-sensitive' mean in semantics?
Some rules depend on surrounding information (e.g., a variable must be declared before use).
32
What is a return type check?
Ensuring a function returns a value consistent with its declared type.
33
What is name resolution?
Determining which declared variable or function a name refers to based on scope rules.
34
What is overloading?
Multiple functions or operators can share the same name but differ by type.
35
What is polymorphism?
The ability of a function to work with multiple types using generic or flexible rules.
36
What is aliasing?
Two different names refer to the same memory location.
37
What is a semantic specification?
Documentation that describes the exact meaning of language constructs.