CD Long Answers

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 37

CD Important Questions

Unit 1

1. Phases of Compilation (VV Imp)


2. Preprocessing directives(preprocessor,linker,loader etc)
3. Regular Grammar
4. Regular expressions
5. LEX lexical analyzer generator
6. Predictive parsing

Unit 2

1. LR-I(CLR)
2. SLR
3. LALR
4. abstract syntax tree
5. Three address codes

Unit 3  

1. SDT -Syntax directed translation


2. SDD
3. Semantic rules
4. Symbol table representation (3types) :Symbol table format
5. Static,Runtime stack and heap storage allocation

Unit 4

1. Optimization techniques
local optimisation
Frequency reduction,folding
Global optimisation
Copy propagation
Optimisation Techniques
M/c dependent and M/c independent techniques
2. DAG construction and representation
3. Data Flow Graph

Block designing
Data flow graph
Data flow equation

Unit 5

1. Object code forms


2. Peephole optimisation
3. Register allocation and assignments
4. generic code generation algorithms
5. Addressing modes
6. Address and Register descriptors
7. Assembly language conversion

Note : Just brief matter is provided for all answers for last minute revision (Some answers may be short and hence it
will not be sufficient if it is written as same in exam as long answer)
All answers mentioned below are just for reference.
CD Unit 1 Important

Unit 1

1. Phases of Compilation (VV Imp)


2. Preprocessing directives(preprocessor,linker,loader etc)
3. Regular Grammar
4. Regular expressions
5. LEX lexical analyzer generator
6. Predictive parsing

Note : Just brief matter is provided for all answers for last minute revision (Some answers may be short and hence it
will not be sufficient if it is written as same in exam as long answer)
All answers mentioned below are just for reference.

1.Phases of Compilation (VV Imp)

Answer : 
2.Preprocessing directives(preprocessor,linker,loader etc)

Answer : 

3.Regular Grammar
Answer :

4.Regular expressions

Answer :

5.LEX lexical analyzer generator


Answer : 

LEX lexical analyzer generator


Lex is a program that generates lexical analyzer. It is used with YACC parser generator. 
The lexical analyzer is a program that transforms an input stream into a sequence of tokens. 
It reads the input stream and produces the source code as output through implementing the lexical analyzer in the C
program.

6.Predictive parsing

Answer : 
Predictive parsers are those recursive descent parsers needs no backtracking
Grammars for which we can create predictive parsers are called LL(1)
The first L means scanning input from left to right 
The second L means leftmost derivation 
And 1 stands for using one input symbol for lookahead

Example : 
CD Unit 2 Important

Unit 2

1. LR-I(CLR)
2. SLR
3. LALR
4. abstract syntax tree
5. Three address codes

Note : Just brief matter is provided for all answers for last minute revision (Some answers may be short and hence it
will not be sufficient if it is written as same in exam as long answer)
All answers mentioned below are just for reference.

1.LR-I(CLR)

Answer : 

Canonical LR Parsing(LR(1))

Example
2.SLR

Answer:

Example :
3.LALR

Answer : 
4.abstract syntax tree

Answer : 

Syntax trees are abstract or compact representation of parse trees. They are also called as Abstract Syntax Trees.
Syntax trees are called as Abstract Syntax Trees because-
They are abstract representation of the parse trees. 
They do not provide every characteristic information from the real syntax. 
For example- no rule nodes, no parenthesis etc.
5.Three address codes

Answer : 
Example
CD Unit 3 Important

Unit 3

1. SDT -Syntax directed translation


2. SDD
3. Semantic rules
4. Symbol table representation (3types) :Symbol table format
5. Static,Runtime stack and heap storage allocation

Note : Just brief matter is provided for all answers for last minute revision (Some answers may be short and hence it
will not be sufficient if it is written as same in exam as long answer)
All answers mentioned below are just for reference.

1.SDT -Syntax directed translation

Reference ->https://www.youtube.com/watch?v=w03voSY4REs  (also use matter from this video)

Answer:

We can associate information with a language construct by attaching attributes to the grammar symbols.
A syntax directed definition specifies the values of attributes by associating semantic rules with the grammar
productions.
2 types
S-attributed SDT
L-attributed SDT
S-attributed SDT
If an SDT uses only synthesized attributes, it is called as S-attributed SDT. These attributes are evaluated using
S-attributed SDTs that have their semantic actions written after the production (right hand side).

As depicted above, attributes in S-attributed SDTs are evaluated in bottom-up parsing, as the values of the
parent nodes depend upon the values of the child nodes.
L-attributed SDT
This form of SDT uses both synthesized and inherited attributes with restriction of not taking values from right
siblings.
In L-attributed SDTs, a non-terminal can get values from its parent, child, and sibling nodes. As in the following
production
S → ABC
S can take values from A, B, and C (synthesized). A can take values from S only. B can take values from S and A.
C can get values from S, A, and B. No nonterminal can get values from the sibling to its right.
Attributes in L-attributed SDTs are evaluated by depth-first and left-to-right parsing manner.
We may conclude that if a definition is S-attributed, then it is also L-attributed as L-attributed definition
encloses S-attributed definitions.

2.SDD -Syntax Directed Definition

Answer :

CFG + semantic rules = Syntax Directed Definitions


A SDD is a context free grammar with attributes and rules 
Attributes are associated with grammar symbols and rules are associated with productions. 
If X is a symbol and a is one of its attributes then we write X.a to denote the value of a at a particular parse tree node
labelled X. 

Eg : 
Attributes may be of many kinds: numbers, types, table references, strings, etc.
Annotated Parse Tree – The parse tree containing the values of attributes at each node for given input string is
called annotated or decorated parse tree.
Features  
High level specification
Hides implementation details
Explicit order of evaluation is not specified
Based on the way the attributes get their values, they can be broadly divided into two categories : synthesized
attributes and inherited attributes.
1. Synthesized attributes
2. Inherited attributes
Synthesized attributes 
These attributes get values from the attribute values of their child nodes. To illustrate, assume the following
production:
S → ABC
If S is taking values from its child nodes (A,B,C), then it is said to be a synthesized attribute, as the values of
ABC are synthesized to S.
Synthesized attributes never take values from their parent nodes or any sibling nodes.
Inherited attributes
In contrast to synthesized attributes, inherited attributes can take values from parent and/or siblings. As in the
following production,
S → ABC
A can get values from S, B and C. B can take values from S, A, and C. Likewise, C can take values from S, A, and
B.
3.Semantic rules 

Answer : 

Did not get theory 

See below problem example

4.Symbol table representation (3types) :Symbol table format

Answer :

Symbol table is an important data structure used in a compiler


Symbol table is used to store the information about the occurrence of various entities such as objects, classes,
variable name, interface, function name etc. it is used by both the analysis and synthesis phases.
The symbol table used for following purposes:
It is used to store the name of all entities in a structured form at one place.
It is used to verify if a variable has been declared.
It is used to determine the scope of a name.
It is used to implement type checking by verifying assignments and expressions in the source code are
semantically correct.
A symbol table can either be linear or a hash table.
Using the following format, it maintains the entry for each name. 
For example, suppose a variable store the information about the following variable declaration:
static int salary then, it stores an entry in the following format: 

The clause attribute contains the entries related to the name.


Types of Symbol Tables
A symbol table can be implemented in one of the following techniques: 
1. Linear (sorted or unsorted) list 
2. Hash table 
3. Binary search tree
Symbol table are mostly implemented as hash table.

Symbol Table Implementation ->  https://www.youtube.com/watch?v=FGKcX9mEYN8

5.Static,Runtime stack and heap storage allocation

Answer : 

Static storage allocation


In static allocation, names are bound to storage locations.
If memory is created at compile time then the memory will be created in static area and only once.
Static allocation supports the dynamic data structure that means memory is created only at compile time and
deallocated after program completion.
The drawback with static storage allocation is that the size and position of data objects should be known at
compile time. 
Another drawback is restriction of the recursion procedure. 

Stack Storage Allocation


In dynamic storage allocation, storage is organized as a stack. 
An activation record is pushed into the stack when activation begins and it is popped when the activation
end. 
Activation record contains the locals so that they are bound to fresh storage in each activation record. The
value of locals is deleted when the activation ends. 
It works on the basis of last-in-first-out (LIFO) and this allocation supports the recursion process.

Heap Storage Allocation


Heap allocation is the most flexible allocation scheme. 
Allocation and deallocation of memory can be done at any time and at any place depending upon the user's
requirement.
Heap allocation is used to allocate memory to the variables dynamically and when the variables are no more
used then claim it back.
Heap storage allocation supports the recursion process.
CD Unit 4 Important

Unit 4

1. Optimization techniques
2. DAG construction and representation
3. Data Flow Graph

Note : Just brief matter is provided for all answers for last minute revision (Some answers may be short and hence it
will not be sufficient if it is written as same in exam as long answer)
All answers mentioned below are just for reference.

1.Optimization techniques

Answer:

The code optimization in the synthesis phase is a program transformation technique, which tries to improve the
intermediate code by making it consume fewer resources (i.e. CPU, Memory) so that faster-running machine code will
result.
Types of Code Optimization
1. Machine Independent Optimization 
This code optimization phase attempts to improve the intermediate code to get a better target code as
the output. The part of the intermediate code which is transformed here does not involve any CPU
registers or absolute memory locations.
2. Machine Dependent Optimization 
Machine-dependent optimization is done after the target code has been generated and when the code
is transformed according to the target machine architecture. It involves CPU registers and may have
absolute memory references rather than relative references. It Divide the problem into basic blocks.
Machinedependent optimizers put efforts to take maximum advantage of the memory hierarchy.

Machine Independent Optimization Techniques


1. Local Optimization
Elimination of Common Subexpressions 
Elimination of copy or variable propagation 

Elimination of dead code


2. Global Optimization
Code motion or movement of code 
It reduces the number of instructions in a loop by moving the instructions outside the loop. It
removes the code by moving the invalid computations outside the loop.
before optimisation

after optimisation
Strength reduction (frequency reduction) and Induction variable
It is a process of replacing the expensive operation by equivalent cheaper operation without
changing the meaning of code. Induction variable is a variable which is used inside the loop and
whose values changes everytime.
Compiler takes more time to excute multiplication operator than addition and subtraction

Constant Folding
It is a process of replacing a constant value into the instructions directly

2.DAG construction and representation

Reference -> https://www.youtube.com/watch?v=fAjIlKmCuUY
Answer : 

DAG is a graphical representation that consist of nodes and leaves. Where nodes represent operators and leaves
represent identifiers(constants and variables)
DAG is generated by 3 address code or intermediate code
Examples
1. (a/b)+((a/b)*(c*d))

2. (a + a * (b - c)) + ((b - c) * d)

3 address code to DAG


Answer :  

3. Data Flow Graph / Data Flow Analysis

includes block designing


data flow equation

Answer : 

Flow Graph:
Flow graph establishes flow of control between blocks.
Flow graph is generated to perform control flow analysis and also used for data flow analysis
 Flow graph is a graphical representation that consists of nodes and edges where nodes represents blocks and
edges represents flow of control between blocks

Basic Block
A block is defined as a set of statements grouped together.
Generally a flowgraph is generated for 3-address code or intermediate code.
The first block in the flowgraph is known as header or starting point.
The last statement where flow of control ends is called a ending point.
Every block is having entry point and exit point.
Basic blocks also have leaders.

Steps for finding the Leaders and constructing the basic blocks

1. First Instruction in 3 address code.


2. Instructions which are targets of unconditional or conditional jump/goto statements are leaders.
3. Instructions which immediately follows unconditional or conditional jump/goto statements are considered
as leaders.
Basic Blocks
Flow Graph is further divide into Reducible and Non Reducible flowgraph
1. Reducible Flow Graph:
The flowgraph which consist of forward and backward edges is called reducible flowgraph.

2. Non reducible flowgraph


The flowgraph which consists of only forward edges is called Non reducible flowgraph.
Data flow Equation
Data Flow analysis collects the information regarding data flow within the program,
Data flow analysis sets the data flow equations at each block to collect the information regarding variable
definition from variable assignment , variable references, redundant instructions, begin instructions, unwanted
instructions and live variables
CD Unit 5 Important

Unit 5

1. Object code forms


2. Peephole optimisation
3. Register allocation and assignments
4. generic code generation algorithms
5. Addressing modes
6. Address and Register descriptors
7. Assembly language conversion

Note : Just brief matter is provided for all answers for last minute revision (Some answers may be short and hence it
will not be sufficient if it is written as same in exam as long answer)
All answers mentioned below are just for reference.

1.Object code forms

Answer : 

Forms of object code:


Various object code forms are 
1. Absolute machine code 
2. Relocatable Machine code
3. Assembly Language Program
Absolute Machine code:
It will be in binary form that can be loaded directly into a fixed location i.e., RAM which can be executed very
easily.
It can be executed by .exe extension which indicates directory executable file.
This code is efficient for only small programs and for the machines which have less space. These will be the
faster one and easy to execute.
Relocatable machine code:
It resembles intermediate code or 3 address code. It is represented by .obj extension. In this sufficient memory
is available.
Assembly Language Program
It is represented by .asm extension.
It consists of mnemonic instructions.

2.Peephole optimisation

Answer :
3.Register allocation and assignments

Answer : 
4.generic code generation algorithms

Answer : 
5.Addressing modes

Answer : Direct from pdf explain with diagrams

6.Address and Register descriptors

Answer : 
7.Assembly language conversion

DID NOT GET

You might also like