CD WINTER 2020 Solution
CD WINTER 2020 Solution
CD WINTER 2020 Solution
1 YouTube:
https://youtube.com/channel/UClk43_DjgTzodjJjumyRlwA
lex.l is an a input file written in a language which describes the generation of lexical
analyzer. The lex compiler transforms lex.l to a C program known as lex.yy.c.
lex.yy.c is compiled by the C compiler to a file called a.out.
The output of C compiler is the working lexical analyzer which takes stream of input
characters and produces a stream of tokens.
There are two parts of the LEX source program −
Auxiliary Definitions
Translation Rules
Auxiliary Definition
It denotes the regular expression of the form.
Translation Rules
It is a set of rules or actions which tells Lexical Analyzer what it has to do or what it has
to return to parser on encountering the token.
2 YouTube:
https://youtube.com/channel/UClk43_DjgTzodjJjumyRlwA
(c) Explain phases of compilers with suitable example.
3 YouTube:
https://youtube.com/channel/UClk43_DjgTzodjJjumyRlwA
4 YouTube:
https://youtube.com/channel/UClk43_DjgTzodjJjumyRlwA
5 YouTube:
https://youtube.com/channel/UClk43_DjgTzodjJjumyRlwA
Q.2 (a) Define terms: pattern, lexeme, token
Pattern: A set of strings in the input for which the same token is produced as output. This set
of strings is described by a rule called a pattern associated with the token.
Lexeme: A lexeme is a sequence of characters in the source program that is matched by the
pattern for a token.
Token: Token is a sequence of characters that can be treated as a single logical entity.
Typical tokens are,
1) Identifiers 2) keywords 3) operators 4) special symbols 5)constants
Description of token
if if if
< or <= or = or < > or >= or
<,<=,= ,< letter
relation >,>=,> followed by letters & digit
A patter is a rule describing the set of lexemes that can represent a particular token in source
program.
(b) Write any one method used in lexical analyzer for buffering the input.
X
6 YouTube:
https://youtube.com/channel/UClk43_DjgTzodjJjumyRlwA
7 YouTube:
https://youtube.com/channel/UClk43_DjgTzodjJjumyRlwA
8 YouTube:
https://youtube.com/channel/UClk43_DjgTzodjJjumyRlwA
Q.3 (a) Consider the following grammar to construct leftmost and right most
derivation for the sentence abab. SaSbS|bSaS|ε
9 YouTube:
https://youtube.com/channel/UClk43_DjgTzodjJjumyRlwA
(b) Write rule(s) to check grammar is left recursive or not. Remove left
recursive from the following grammar.
10 YouTube:
https://youtube.com/channel/UClk43_DjgTzodjJjumyRlwA
(c) Construct the SLR parsing table for the following Grammar.
E E+T | T
T T*F | F
F (E) | id
Example
EE A E | id
A + | *
The above grammar is not an operator grammar but we can convert that grammar into operator
grammar like −
E E + E | E * E | id
11 YouTube:
https://youtube.com/channel/UClk43_DjgTzodjJjumyRlwA
(b) Explain any two error-recovery strategies.
12 YouTube:
https://youtube.com/channel/UClk43_DjgTzodjJjumyRlwA
13 YouTube:
https://youtube.com/channel/UClk43_DjgTzodjJjumyRlwA
(c) Construct LALR parsing table for the following grammar.
S CC C cC C d
14 YouTube:
https://youtube.com/channel/UClk43_DjgTzodjJjumyRlwA
15 YouTube:
https://youtube.com/channel/UClk43_DjgTzodjJjumyRlwA
Q.5 (a) Define: 1) synthesized attribute 2) inherited attribute
1) synthesized attribute
Synthesized attribute is an attribute whose parse tree node value is determined by the attribute
value at 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 attribute is used by both S-attributed SDT and L-attributed STD.
2) inherited attribute
On other hand an attribute is said to be Inherited attribute if its parse tree node value is
determined by the attribute value at parent and/or siblings node.
In case of S → ABC if 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 then S is said to be Inherited Attribute.
Inherited attribute is used by only L-attributed SDT.
16 YouTube:
https://youtube.com/channel/UClk43_DjgTzodjJjumyRlwA
(b) Explain any two parameter passing methods.
Or b) Explain the following parameter passing methods. 1. Call-by-value 2.
Call-by-reference 3. Copy-Restore 4. Call-by-Name (WINTER 2021 Q.4-b)
17 YouTube:
https://youtube.com/channel/UClk43_DjgTzodjJjumyRlwA
18 YouTube:
https://youtube.com/channel/UClk43_DjgTzodjJjumyRlwA
(c) Write SDD for arithmetic expression and Construct annotated parse tree
for the input expression (4*7+1)*2 .
X
19 YouTube:
https://youtube.com/channel/UClk43_DjgTzodjJjumyRlwA
Q.6 (a) What is activation record?
An activation record contains all the necessary information required to call a procedure. An
activation record may contain the following units.
(b) What is Intermediate form of the code? What are the advantages of it?
During the translation of a source program into the object code for a target machine, a
compiler may generate a middle-level language code, which is known as intermediate code or
intermediate text.
The complexity of this code lies between the source language code and the object code.
The intermediate code can be represented in the form of postfix notation, syntax tree, directed
acyclic graph (DAG), three-address code, quadruples, and triples.
20 YouTube:
https://youtube.com/channel/UClk43_DjgTzodjJjumyRlwA
The intermediate code allows the machine-independent optimization of the code. Several
specialized techniques are used to optimize the intermediate code by the front end of the
compiler.
Syntax-directed translation implements the intermediate code generation; thus, by augmenting
the parser, it can be folded into the parsing.
(c) Construct syntax directed translation scheme and definition that translate arithmetic
operation from infix to postfix in which an operator appears before its operand as for
example xy- is a positive notation for x-y . Give annotated parse tree for the input 9-5+2
21 YouTube:
https://youtube.com/channel/UClk43_DjgTzodjJjumyRlwA
22 YouTube:
https://youtube.com/channel/UClk43_DjgTzodjJjumyRlwA
Q.7 (a) Explain any two issues in design of code generator.
23 YouTube:
https://youtube.com/channel/UClk43_DjgTzodjJjumyRlwA
24 YouTube:
https://youtube.com/channel/UClk43_DjgTzodjJjumyRlwA
(b) Compare: static v/s dynamic Memory Allocation.
25 YouTube:
https://youtube.com/channel/UClk43_DjgTzodjJjumyRlwA
(c) Translate the expression –(a+b)*(c+d)+(a+b+c) into
26 YouTube:
https://youtube.com/channel/UClk43_DjgTzodjJjumyRlwA
(b) Write a short note on Symbol table management.
Symbol table is an important data structure created and maintained by compilers in order to
store information about the occurrence of various entities such as variable names, function
names, objects, classes, interfaces, etc.
Symbol table is used by both the analysis and the synthesis parts of a compiler.
A symbol table may serve the following purposes depending upon the language in hand:
27 YouTube:
https://youtube.com/channel/UClk43_DjgTzodjJjumyRlwA
28 YouTube:
https://youtube.com/channel/UClk43_DjgTzodjJjumyRlwA
(c) Write any two methods of code-optimization in detail.
29 YouTube:
https://youtube.com/channel/UClk43_DjgTzodjJjumyRlwA
30 YouTube:
https://youtube.com/channel/UClk43_DjgTzodjJjumyRlwA
31 YouTube:
https://youtube.com/channel/UClk43_DjgTzodjJjumyRlwA