System Programming Pyqs
System Programming Pyqs
System Programming Pyqs
Section A
Question 1 :-
(a) What is a load-and-go type assembler ?? How is it used
in program development ?
Ans.)
Question 2 :-
(a) What are the major tasks of a Linker during
program development ?
Ans.)The major task of a linker is to search and locate referenced module/routines
in a program and to determine the memory location where these codes will be
loaded, making the program instruction to have absolute references.
(b) What is relocation ? Explain different ways by -which
assembler can pass relocation information to the linker.
Ans.)
Question 3 :-
Write the regular expressions for the following
(a) A number string (non-empty sequence of decimal
digits) that has a value strictly greater than 65. Assume
that leading zeroes are allowed.
ANS->
(b) A set of strings of a's and b's where number of b's
is a multiple of three and there can be any number
of a's.
ANS->
(a*ba*ba*ba*)*
(c ) All strings of letters that contain the five vowels in
Order.
ANS->
Letter ->[b-d f-h j-n p-t v-z]
Question 4 :-
(a) What is the purpose of yytext and yyleng variahles
in a LEX program
ANS->
A string named yytext. This string contains a sequence of
characters making up a single input token. The token is read from
the stream yyin, which, by default, is the standard input (stdin).
(0) S' → S
(1) S → iSeS
(2) S → iS
(3) S→a
Parse the input string iiaea using the above parsing table.
Question 6 :-
(a) What is Syntax-Directed Translation ? What is it used
for ? (page304)
A syntax-directed defnition (SDD) is a context-free grammar together
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 labeled X .
Question 7 :-
(a) What is an activation record ?
an activation record is used to store information about the status of the
machine, such as the value of the program counter and machine
registers, when a procedure call occurs.
OR
An Activation Record is a data structure that is activated/ created when a
procedure/function is invoked, and it includes the following data about the function.
Section B
Question 8 :-
(a) What are the steps taken by a single pass assembler if
the type of the mnemonic encountered in a parsed line of
an assembly language program specifies a machine
instruction?
%%
[a-zA-Z]+ { len=strlen(yytext);
if(len > 3)
{counter++;} }
%%
int main()
{
printf("Enter the string:");
yylex();
printf("\n %d", counter);
return 0;
}
b)
Question 10 :-
Consider the context-free grammar.
S → aX
X → bX | bY
Y→c
The symbols S,X,Y are non-terminals and S is the start symbol
while a, b and c are terminal symbols.
(i) Give the canonical collection of LR (0) items for this
Grammar.
Ans.)
Question 11 :-
(a) Consider the following syntax-directed definition over
the grammar defined by G where S, A, Sign are
non-terminals. There is a special terminal symbol "n" that
is lexically matched by any string of one numeric digit
and whose value is the numeric value of decimal
representation
Identify the attributes associated with the grammar
symbols and classify them as synthesized and inherited.
Ans.)
Question 13 :-
(a) Briefly explain the structure of an activation record.
How is variable length array allocated memory in the
stack of activation records ?
Page 433-434
Page 438-439
Section A
Question 1 :-
(a) Briefly explain a hybrid compiler with the help of an
example.
Ans.)
Question 2 :-
(a) What are the main objectives of the linking process?
(b) What-are the advantages and disadvantages of a load-
and-go type assembler?
Ans.)
Question 3 :-
(a) Describe the structure of a Lex program.
A Lex program has the following form:
declarations
%%
translation rules
%%
auxiliary functions
Question 4 :-
(a) Mention two rules that Yacc uses to resolve parsing
action conflicts.
Ans.)Unless otherwise instructed, yacc resolves all parsing action
conflicts using the following two rules: A reduce/reduce conflict is
resolved by choosing the conflicting production listed first in the
Yacc specification. A shift/reduce conflict is resolved in favor of
shift.
Question 5 :-
(a) Give three address code for the following arithmetic
expression:
a=b+(-c)
Question 6 :-
(a) Differentiate between absolute and relocatable machine
language programs.
Pg no 508
(b) What is the use of heap storage allocation strategy?
Data that may outlive the call to the procedure that created it is usually
allocated on a “heap” of reusable storage. The heap is an area of virtual
memory that allows objects or other data elements to obtain storage
when they are created and to return that storage when they are
invalidated.
(c) What does cost of a program mean? List down some
common cost measures for a program.
(d) Differentiate between static and shared libraries.
Section B
Question 7 :-
(a) What is backpatching in a single pass assembler. How
does it solve the problem of forward referencing?
Question 8 :-
(a) Draw a flow diagram to show different phases of the
front end of a compiler.
(b)
(c) Explain different components of binary image
produced
Ans.)
Question 9 :-
Consider the following context-free grammar:
E' → E
E → EaT | T
T → TF | F
F → Fb | c
(a) Construct the canonical collection of LR(0) items. Note
that the grammar is already augmented, and E' is the new
start symbol.
Ans.)
(b) Using part (a), build the SLR(1) parsing table for this
grammar.
Ans.)
Question 10 :-
(a) Consider the following syntax-directed definition:
PRODUCTION SEMANTIC RULE
array(3,array(4,array(5,integer)))
Int[3][4][5]
(c) Define kernel items and non-kernel items of LR(0)
items.
Ans.)Kernel items, which include the initial item, S'→ . S, and
all items whose dots are not at the left end. Non-kernel items,
which have their dots at the left end.
Question 11 :-
(a) Consider the following context-free grammar
S → aSbS
S→a
S→c
Is the grammar LR(1)? Justify your answer.
Ans.)
Section A
Question 1 :-
(a) Differentiate between static and shared libraries.
Done
Question 2 :-
Discuss the major data structures and their organization, used
in an assembler.
Question 3 :-
(a) Consider the following grammar:
S→AB
S→ASB
A→a
B→b
Are the foltowing sentences valid according to the-above
grammar? If yes, derive them.
(i) aabb
i) Yes ,
(ii) abba
II) No,
Question 4 :-
Write a Lex program that converts all lower case letters to
uppercase in a text File.
%{
#include<stdio.h>
%}
%%
/*** Rules section ***/
[a-z] printf("%c",yytext[0] - ('a' - 'A'));
0 { return 0;}
%%
int main()
{
FILE *fp;
fp = fopen("test.txt", "r");
if (fp == NULL) { printf("File not found"); }
yyin = fp;
yylex();
return 0;
}
Question 5 :-
Describe the languages denoted by the following regular
expressions!*hey
(i) (a|b)*a(a|b)(a|b)
All strings of a’s and b’s, with an a in the 3rd letter from the right.
(ii) a*b*c*d*........z*
All strings of lowercase letters in which the letters in are in ascending
lexicographic order.
(iii) b*(ab*ab*)*
All strings of a’s and b’s with an even number of a’s.
(iv) a*b*a*b*a*b?a*
All strings of a’s and b’s that contain just two or three b`s
(v) (a|b)*b(a|b)*b(a|b)*
All strings of a’s and b’s that contain at least two b's.
Question 6 :-
(a) What are the advantages of LALR over Canonical LR
parsers?
Ans.) an LALR parser is quite efficient at finding the single correct
bottom-up parse in a single left-to-right scan over the input stream,
because it does not need to use backtracking.
(b) Differentiate between synthesized àttributes and
inherited attributes with the help of'an example.
Ans.) 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.
Question 7 :-
(a) Translate the following arithmetic expression into:
a[i]=b*c-b*d
(i) Quadruples
(ii) Triples
Section B
Question 8 :-
(a) What is Position Independent Code? What are its
advantages over ordinary executables?
Ans.)
char * a;
a= &x;
x= 1xab; }
In this code, 1xab is neither a number nor an identifier. So this code will
show the lexical error.
Question 10 :-
Consider the following grammer
S→aX
X → bX | bY
Y→c
The symbols S, X, Y are non-terminals and S is the start
symbol while a, b and c are terminal symbols.
(a) Give the canonical LR(0) set of items for the above
grammar.
(b) Compute the FOLLOW sets for all non-terminals. and
give the SLR parsing table (action and goto) for this
grammar.
Ans.)
Question 11 :-
(a) Consider the following grammar:
S→SS+
S → S S*
S→a
Indicate the handle in each of the right sentential forms
and give the bottom up parse for 3rd.
(i) SSS+a*+
(ii) SS+a*a+
(ili) aaa*a++
Possible handles for G are SS+, SS* or `a`. Each sentential form has
multiple handles. Note that the handle must be followed by terminals.
If you still have a choice, always pick the leftmost handle. Why?
Because
in a bottom-up parse (rightmost derivation), the leftmost nonterminals
are reduced first. Thus
a) S[SS+]a*+ // the leftmost handle is SS+
b) [SS+]a*a+ // the leftmost handle is SS+
c) [a]aa*a++ // the leftmost handle is the leftmost `a`
Question 12 :-
(a) Briefly explain the structure of an activation record.
Differentiate between the two different types of links (that
connect to other activation records) present in the
activation record with the help of an example.
(b) Generate code for the following three-address
statements (in sequence) assuming a is an array whose
elements are 4-byte values:
x=a[i]
i)for x=a[i]
LD R1, i // R1 = i
MUL R1, R1 , 4 // R1 = R1 *4
LD R2 , a(R1) // R2 = contents(a + contents(R1))
ST x, R2 // x = R2
z=x*y
ii) LD R1, x
LD R2, y
MUL R1, R1, R2 // R1 = R1 * R2
ST z, R1
Question 13 :-
Consider the following augmented grammar:
S' → S
S → id
S → V=E
V → id
(a) Construct the LR (1) parsing table:
(b) Parse the input string id=id using the constructed
parse table.
Ans.) given grammar is wrong.
2019 PYQ
Section A
Question 1 :-
(a) Explain forward reference in assembler with the help of
an example.
Ans.) Page no. -19 - ch3 assembler.
(b) Draw the activation tree for the function calls:
main (){pl();}
pI( ){p2( ); p3( );}
p2(){}
р3(){}
ANS)
LD R1, x
LD R2, y
SUB R1, R1, R2
BLTZ R1, L1
LD R1, #1
ST z, R1
BR L2
L1: LD R1, #1
ST z, R1
L2: LD R1, #2
ST z, R1
Section B
Question 2 :-
(a) Consider the following scetion tables for two objeet
files k.obj and y.obj. After Pass 1 of linking process, show
the content of appropriate data structures formed and
also show the layout of the final exccutable module.
Page no 293
Question 3 :-
(a) What is Position Independent Code?
(b) Consider the augmented expression grammar
E→E
E→E+T|T
T→T*F|F
F → id
Construct the LR(0) automaton and parse the input string id *id
using shift/reduce parser.
Question 4 :-
(a) Write a type expression for an "array of 4 arrays of 3
integers each".
int [4][3]
array(4,array(3,integer))
array
/ \
4 array
/ \
3 integer
(b) What are the benefits of using quadruple over the triple
in three address code generator?
Ans.)A benefit of quadruples over triples can be seen in an
optimizing compiler,where instructions are often moved around.
With quadruples, if we move an instruction that computes a
temporary t, then the instructions that use t require no change. With
triples, the result of an operation is referred to by its position, so
moving an instruction may require us to change all references to
that result.
Question 5 :-
(a) Consider the grammar:
S → BC | DA
C → AA
B→b
A→a
D → ba
Construct LALR parsing table for the above grammar.
(b) What are the limitations of Load-and-Go Assembler?
Question 6 :-
(a) Consider the Syntax Directed Definitions :
T → T1 * F { T.val = T1. val × F. val }
E → T { E. val = T. val }
E → E1 + T { E. val = E1. val + T. val }
T → F { T. val = F. val }
F → G ↑ F { F. val = POWER(F. val, G. val) }
F → G { F. val = G val }
G → digit { G. val = digit.lexval }
Construct annotated parse tree for 1 * 3 ↑ 2 + 5 * 3 and give the
output.
Example :
(c) Compare and contrast single-pass and two-pass
assemblers.
Ans.)Difference between One Pass and Two Pass
Assemblers:-
The difference between one pass and two pass assemblers are:-
A one pass assembler passes over the source file exactly once, in the same pass
collecting the labels, resolving future references and doing the actual assembly. The
difficult part is to resolve future label references (the problem of forward referencing)
and assemble code in one pass. The one pass assembler prepares an intermediate
file, which is used as input by the two pass assembler.
A two pass assembler does two passes over the source file (the second pass can be
over an intermediate file generated in the first pass of the assembler). In the first
pass all it does is looks for label definitions and introduces them in the symbol table
(a dynamic table which includes the label name and address for each label in the
source program). In the second pass, after the symbol table is complete, it does the
actual assembly by translating the operations into machine codes and so on.
Question 7 :-
(a) What is the output of the following code?
int f(int x, int * y, int ** z)
{
**z+=1;
*y+=2;
x+=3;
return x + *y + **z;
}
int main( )
{
int x, c, *b, **a;
c = 4, b = &c, a = &b;
x=f(c, b, a);
printf("%d", x);
return 0;
}
Output : 21
(b) "Values communicated between caller and callee are
placed in the beginning of callee's activation record."
Why?
Values communicated b etween caller and callee are generally
placed at the beginning of the callee's activation record, so they are
as close as possible to the caller's activation record. The motivation
is that the caller can compute the values of the actual parameters of
the call and place them on top of its own activation record, without
having to create the entire activation record of the callee, or even to
know the layout of that record. Moreover, it allows for the use of pro
cedures that do not always take the same numb er or typ e of
arguments, such as C's printf function. The callee knows where
to place the return value, relative to its own activation record, while
however many arguments are present will appear sequentially b
elow that place on the stack.
(c) Determine the cost of each instruction in the following
assembly code. Assume that each memory access
(including the machine instruction) has cost 1.
LD RO, i
MUL RO, R0,8
LD R1, a(R0)
ST b, R1
Cost : 2 + 2 + 2 + 2 = 8