Semantic analysis Flashcards

1
Q

what grammar symbols associated with?

A

attributes

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

how are these attributes evaluated?

A

semantic rules

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

Evaluation of these semantic rules depends on :

A
Generate intermediate codes
put information on the symbol table
perform type checking
issues error messages
perform almost any activities
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

A_________checks the source program for semantic errors

A

semantic analyzer

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

A semantic analyzer collects information for ____________

A

Code Generation

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

________________ is an important part of the semantic analyzer

A

Type-checking

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

SDT

A

Syntax directed translation

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

how are attributes stored in SDT?

A

The attributes are attached to the grammar symbols

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

How are the values of the attributes calculated?

A

Semantic rules associated with grammar productions

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

The flow of the semantic compiler

A

input string->parse tree-> dependency graph->semantic rule evaluation order

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

Attribute values may represent :

A
Numbers
strings
memory locations
A data type for checking expressions
scoping information for declaration
A data type for checking expressions
scoping information for local declarations
Intermediate program representations
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Name two ways to represent semantic rules:

A

Syntax directed definitions.

& Translation Schemes

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

SDD are ____ level

Translation schemes are closer to an _____________

A

higher implementation

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

Explain SDD

syntax-directed definitions

A

Each production of A->alpha
is associated with the set of semantic rules
b=f(c1,c2,…….cn) where f is a function
b=> is synthesized attribute of A and c1,c2,c3,,,,,,,,,,cn are attributes of the grammar symbols in the production
b=>inherited attribute,one of the grammar symbols in aplha are attributes of the grammar symbols in the production (A-> alpha)

in either of the cases, we say b depends on c1,c2,c3,,,,,,,,,,,ck.

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

what are Synthesized attributes

A

Synthesized attributes are the depends only on the attributes of the children
They are the most common attribute type
Synthesized attributes never take values from their parents nodes or any sibling nodes
the non terminal concerned must be in the head of the production
Terminals have synthesised attributes which are the lexical values

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

what has Inherited attributes?

A

An Attributes’ node ‘s parents and/or siblings .They cannot be defined in terms of attributes value at children nodes

Inherited attributes are often used in compilers for passing contextual information forward ,for example,the type keyword in a variable declaration statement

17
Q

Attribute Grammar

A

A semantic rule=f(c1,c2,c3,,,,,,,,,cn) indicates that the attribute b depends on attributes c1,c2,…………cn.

Syntax-directed definition a semantic rule may just evaluate a value of an attribute it it may have some side effects such as printing values

18
Q

Side effects

A

Side effects:
Evaluation of semantic rules may generate intermediate codes,may perform type checking and may issue error messages.
These are known as side effects

19
Q

what are semantic rules with controlled side effects

A

Attribute grammars have no side
effects and allow any evaluation order consistent with dependency graph
whereas translation schemes impose left-to-right evaluation and allow
schematic actions to contain any program fragment

20
Q

ways to control side effects:

A
  1. Permit incidental side effects that do not disturb attribute evaluation.
  2. Impose restrictions on allowable evaluation orders, so that the same
    translation is produced for any allowable order
21
Q

what is the need for a dependency graph?

A

An SDD with both and synthesized attributes does not ensure any guaranteed order ,even it may not have an order at all
non terminals A and B with synthesized and inherited attributes A.s and B.i respectively along with the production and rules as:
Production
A →B

Semantic Rule
A.s = B.i
B.i= A.s+1

22
Q

what is the Dependency graph?

A

1.Dependency graph predicts the flow of information among the attribute instances in a particular parse tree

2.The inter dependencies among the inherited and synthesized attributes
at the node in the parse tree is depicted by dependency graph.

23
Q

Visualize a Dependency Graph

A
  1. Each attribute is a node

2. We add edges from the node for attribute c to the node for the attribute