chapter 4 - 6 Flashcards

1
Q

Semantic analysis checks the source program for syntactic errors.

A

False

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

Type checking ensures that operators are used with operands of permitted types.

A

t

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

A semantic analyzer can identify undeclared variables.

A

True

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

Syntax-directed translation involves both semantic rules and syntax rules.

A

True

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

Synthesized attributes depend on the attributes of the parent node.

A

False

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

Inherited attributes can be evaluated using a bottom-up traversal of the parse tree.

A

f

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

A topological sort of a dependency graph helps in determining the evaluation order of attributes.

A

t

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

Dynamic checks are performed during the execution of the program.

A

t

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

L-attributed grammars use only synthesized attributes.

A

f

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

Which of the following is a task performed during semantic analysis?

A. Lexical analysis
B. Type checking
C. Token generation
D. Code optimization

A

Answer: B

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

Semantic errors include:

A. Type mismatch
B. Syntax errors
C. Token errors
D. Memory allocation errors

A

Answer: A

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

What is the primary purpose of syntax-directed translation?

A. To optimize machine code
B. To guide the translation of source code using context-free grammars
C. To generate lexical tokens
D. To perform runtime error checking

A

Answer: B

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

In syntax-directed translation, what is the role of the parse tree?

A. To optimize the source code
B. To perform lexical analysis
C. To direct semantic analysis and intermediate code translation
D. To generate machine code

A

Answer: C

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

What is an attributed grammar?

A. A grammar that generates parse trees
B. A grammar that includes information to control semantic analysis and translation
C. A grammar used only for lexical analysis
D. A grammar used for error handling

A

Answer: B

  • we can augment the CFG with information to control the semantic analysis and translation process.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

In syntax-directed translation, what does the set of semantic actions enclosed by { } indicate?

A. The rules for lexical analysis
B. The steps for generating machine code
C. The semantic actions performed for each production
D. The optimization steps for the source code

A

Answer: C

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

Which of the following describes the output action in syntax-directed translation?

A. Generation of intermediate code
B. Printing of an error diagnostic
C. Placement of some values in a table
D. Computation of values for variable belonging to the
compiler
E. All

A

E. All

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

What is an attributed CFG?

A. A context-free grammar without semantic rules
B. A CFG with associated semantic rules for computing attribute values
C. A CFG used for lexical analysis
D. A CFG that generates machine code

A

Answer: B
- found in Syntax Directed Definitions

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

In an attributed grammar, what does an annotated parse tree represent?

A. The syntactic structure of the source code
B. The optimized version of the source code
C. A parse tree with a field for each attribute at each node
D. The intermediate code

A

Answer: C

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

What is the purpose of semantic rules in a syntax-directed definition?

A. To check for syntax errors
B. To compute the values of attributes
C. To perform lexical analysis
D. To generate machine code

A

B

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

Which of the following is an example of a semantic rule in an attributed CFG?

A. E → E + T
B. T.v → id.v
C.E.v = E.v + T.v
D. E1.v = E2.v + T.v

A

Answer: D

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

Semantic actions in syntax-directed translation are always performed after the parse tree is completely built.

A

False

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

What is a synthesized attribute?

A. An attribute of the parent depending on the children
B. An attribute of the children depending on the parent
C. An attribute related to syntax rules
D. An attribute of the parent depending on the children and the parent node itsself

A

Answer: D

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

In a syntax-directed translation, what is typically associated with each production?

A. Tokens
B. Parse trees
C. Semantic actions
D. Intermediate code

A

Answer: C

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

Which attribute type can only depend on the parent or siblings of a node?

A. Synthesized attributes
B. Inherited attributes
C. Lexical attributes
D. Terminal attributes

A

Answer: B

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

Inherited attributes, Attribute of a node is defined in terms of Attribute values at left siblings

A

True.
Never right

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

Terminals can have _________ attributes

A

synthesized attributes, but not inherited attributes

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

A dependency graph is used to:

A. Show the syntax structure of a program
B. Determine the lexical tokens of a program
C. Show the flow of information for attribute evaluation
D. Optimize the code generation process

A

Answer: C

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

Which method evaluates L-attributed definitions by mixing post-order and pre-order traversal?

A. S-Eval
B. T-Eval
C. L-Eval
D. G-Eval

A

Answer: C

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

Static checks are performed:

A. During program execution
B. At compile time
C. During linking
D. During lexical analysis

A

Answer: B

30
Q

Which of the following is not an example of a static check?

A. Type checks
B. Array out of bounds checks
C. Flow-of-control checks
D. Uniqueness checks

A

Answer: B

31
Q

Dynamic checks include:

A. Type checks
B. Uniqueness checks
C. Division by zero
D. Name-related checks

A

Answer: C

32
Q

An L-attributed definition is a syntax-directed definition that uses:

A. Only synthesized attributes
B. Both synthesized and inherited attributes
C. Only inherited attributes
D. Lexical attributes

A

Answer: B

33
Q

The type checker in a compiler verifies:

A. Lexical correctness of tokens
B. Syntactic correctness of expressions
C. Type correctness of constructs
D. Optimization of the code

A

Answer: C

34
Q

In syntax-directed translation, intermediate code generation is often associated with:

A. Lexical analysis
B. Syntax rules
C. Semantic rules
D. Symbol table management

A

Answer: C

35
Q

A grammar that only uses synthesized attributes is called:

A. L-attributed grammar
B. S-attributed grammar
C. Inherited grammar
D. Terminal grammar

A

Answer: B

36
Q

Which of the following tasks is not typically part of semantic analysis?

A. Type checking
B. Array-bound checking
C. Intermediate code generation
D. Scope resolution

A

Answer: C

37
Q

A semantic rule is:

A. A rule that defines the syntax of a language
B. A rule that determines the type of tokens
C. A rule that associates attributes with grammar symbols
D. A rule that optimizes the generated code

A

Answer: C

38
Q

Which of the following is true for S-attributed definitions?

A. They use only inherited attributes
B. They can be evaluated by a bottom-up parser
C. They require a dependency graph for evaluation
D. They are less efficient than L-attributed definitions

A

Answer: B

39
Q

What does an annotated parse tree include?

A. Only syntactic information
B. Only lexical information
C. Both syntactic and semantic information
D. Only optimized code

A

Answer: C

40
Q

Which phase of the compiler is responsible for creating the symbol table?

A. Lexical analysis
B. Syntax analysis
C. Semantic analysis
D. Code generation

A

Answer: A

41
Q

What is the purpose of intermediate code generation in a compiler?

A. To provide a machine-independent representation of the source program
B. To generate the final machine code
C. To perform lexical analysis
D. To optimize the source code

A

Answer: A

42
Q

Which method is commonly used for attribute evaluation in L-attributed grammars?

A. Post-order traversal
B. Pre-order traversal
C. Depth-first traversal
D. Topological sort

A

Answer: D

43
Q

What does a topological sort of a dependency graph determine?

A. The order of parsing
B. The order of code generation
C. The order of attribute evaluation
D. The order of syntax analysis

A

Answer: C

44
Q

Which of the following is true about inherited attributes?

A. They are passed from children to parent nodes
B. They can be evaluated using a bottom-up approach
C. They are passed from parent or sibling nodes
D. They are only used in dynamic checks

A

Answer: C

45
Q

Give Examples of static checks

A

□ Type Checks - Checks if an operator has the right type of operands

□ Flow-of-Control Checks - Statements that cause flow of control to leave a construct must
have some place to which to transfer the flow of control

□ Uniqueness Checks - object must be defined exactly once

□ Name-Related Checks

46
Q

Which of the following is not typically stored in the symbol table?

A. Variable names
B. Scope information
C. Intermediate code
D. Data types

A

Answer: C

47
Q

In the context of semantic analysis, a type lattice is used to:

A. Represent the hierarchical relationships between different types
B. Perform syntax analysis
C. Generate lexical tokens
D. Optimize intermediate code

A

Answer: A

48
Q

Which of the following is a characteristic of strongly typed languages?

A. Type checking is done at runtime
B. Type checking is done at compile time
C. Variables can change their type at runtime
D. Type errors are ignored

A

Answer: B

49
Q

________ is A formal way to define attributes for programming languages

A

attribute grammar

50
Q

In a dependency graph, what does a node represent?

A. A lexical token
B. A grammar rule
C. An attribute
D. A semantic error

A

Answer: C

51
Q

Which traversal method is typically used for evaluating synthesized attributes in S-attributed grammars?

A. Pre-order traversal
B. Post-order traversal
C. In-order traversal
D. Level-order traversal

A

Answer: B

52
Q

What is the primary advantage of using intermediate code in a compiler?

A. It speeds up lexical analysis
B. It simplifies syntax analysis
C. It makes the compiler portable
D. It reduces the size of the symbol table

A

Answer: C

53
Q

Which of the following is an example of a semantic error?

A. Missing semicolon
B. Using a variable before declaring it
C. Unmatched parentheses
D. Mismatched data types in an operation

A

Answer: D

54
Q

In syntax-directed translation, what is an action performed by semantic rules?

A. Token generation
B. Syntax analysis
C. Intermediate code generation
D. Error recovery

A

Answer: C

55
Q

What is a common use of synthesized attributes?

A. To store error messages
B. To calculate values bottom-up in the parse tree
C. To manage scope information
D. To perform runtime checks

A

Answer: B

56
Q

Which of the following correctly describes an inherited attribute?

A. An attribute that is calculated using values from child nodes
B. An attribute that is passed from parent to child nodes
C. An attribute used for lexical analysis
D. An attribute used for code optimization

A

Answer: B

57
Q

In a dependency graph, an edge from node A to node B means:

A. A depends on B
B. B depends on A
C. Both A and B are independent
D. A and B are mutually dependent

A

Answer: B

58
Q

Synthesized attributes are typically evaluated in a top-down manner.

A

f

59
Q

An inherited attribute of a node can depend on the attributes of its parent node.

A

t

60
Q

A dependency graph with cycles indicates that the attribute evaluation order is not well-defined.

A

t

61
Q

The evaluation order of attributes in an attribute grammar is determined by the parse tree traversal order.

A

f

62
Q

In syntax-directed translation, semantic actions are executed during the parsing process.

A

t

63
Q

What are basic types? Give three examples.

A

Basic types are atomic types that have no internal structure as far as the programmer is concerned. Examples include integer, real, boolean, character, and enumerated types.

64
Q

What are constructed types? Name three examples.

A

Constructed types include arrays, records, sets, and structures constructed from basic types and/or other constructed types. Examples include arrays, pointers, and functions.

65
Q

What factors does the design of a type checker depend on?

A

The syntactic structure of language constructs (e.g., operator)

The type expressions of the language (e.g., int, float, array)

The rules for assigning types to constructs (e.g., if both operands of + are int, the result is int).

66
Q

Define a type expression and give an example of a basic type expression.

A

A type expression is either a basic type or formed by applying an operator called a type constructor to the type expression. Example: int.

67
Q

What is a type constructor? Give an example.

A

A type constructor is an operator that forms a type expression when applied to a type expression. Example: ptr:*int (pointer to integer).

68
Q

How is an array type expression formed? Give an example.

A

If I is an index set and T is a type expression, then array(I, T) is a type expression. Example: array[1..10] of int is array(10, int).

69
Q

What is a type system?

A

A type system is a collection of rules for assigning type expressions to the various parts of a program.

70
Q

What is a sound type system?

A

A sound type system is one where any program that passes the static type checker cannot contain run-time type errors. Such languages are said to be strongly typed.

71
Q

What is structural equivalence?

A

Two type expressions are structurally equivalent if they are the same basic types or are formed by applying the same constructor to structurally equivalent types.

even if they are named differently.

72
Q

What is coercion in type conversion?

A

Coercion is implicit type conversion done by the compiler.