Study Guide Primary Topics Flashcards

1
Q

What is semantic analysis?

A

The phase of the compiler that checks the source program for semantic consistency with the language definition.

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

What is a synthesized attribute?

A

Of a non terminal A at a parse tree node N is directly defined by a semantic rule associated with production at N (node value determined from child node(s))

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

What is an inherited attribute?

A

For a nonterminal B at a parse-tree node N is defined by a semantic rule associated with the production at the parent of N (node gets value from parent/sibling nodes)

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

What are attribute grammars?

A

Syntax-defined definitions whose semantic rules have no side effects.

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

What is a side effect?

A

Any action or rule application that results in an effect, such as printing or evaluating a value.

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

What is the purpose of the semantic analyzer?

A

Checking and verifying data types. Last chance to weed out inconsistent/incorrect programs at the front end.

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

What are the jobs of the semantic analyzer (know at least 3)

A
  1. Type checking
  2. Type coercion/conversion
  3. Variable deceleration and use
  4. Access control and scope checking
  5. Function parameter count and consistency
  6. Store discovered/synthesized/inherited attributes in the IR or symbol table
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is intermediate representation?

A

Data structure used by compiler to represent source code.

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

What are data types?

A

A collection or grouping of data values and the operations that can be performed on them.

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

What is a type system?

A

feature of a language, the collection of all its data types, data operations, and rules for how types can be combined or coerced

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

Language Type: Static

A

Type-checking performed at compile time.

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

Language Type: Dynamic

A

Type checking performed at run time

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

Language Type: Explicit

A

Types declared in source code

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

Language Type: Implicit

A

Type checking in compiler

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

Language Type: Safe

A

Cannot violate rules and structure of type system

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

Language Type: Unsafe

A

Can violate rules and structure of type system

17
Q

Language Type: Atomic

A

Types provided by language and recognized by compiler

18
Q

Language Type: Composite

A

Types that are built up from atomic types

19
Q

Why do we use data types?

A

They give us a way of specifying the context of data

20
Q

Why do we use type systems?

A

Ensures that everything is typed and all types agree with each other

21
Q

Benefits of a type system?

A

Correctness, performance, expressiveness

22
Q

What is data flow analysis?

A

Process of tracing how values make their way through a program

23
Q

What are the benefits (3) of data flow analysis?

A
  1. Knowing when data is alive and in-scope (visible)
  2. Knowing if a variable changes and when/if it changes at all
  3. Knowing if a variable is declared but never used
24
Q

What is code generation/what does it do?

A

Takes intermediate representation, translates into machine code.
optimized TAC → code generation → machine code

25
Q

What kind of optimizations can be done? Know three

A

Constant folding
Copy propagation
Reduction in strength
Substitution of in-line code
Common subexpression elimination
Loop optimization