system dp mukesh 2003
TRANSCRIPT
-
8/8/2019 System Dp Mukesh 2003
1/13
DESIGN PROBLEM-1
OF
SYSTEM PROGRAMMING
Submitted to: Submitted by:Submitted to: Submitted by:
RUCHI VINAYAK MukeshRUCHI VINAYAK Mukesh
SamtaSamta
B.techB.tech
(H)-CSE(H)-CSE
Section:Section:
A1802A1802
-
8/8/2019 System Dp Mukesh 2003
2/13
Roll No.:Roll No.:
RA1802B29RA1802B29
Ques:-Implement all the steps of a compiler for the following
program module:
while (AD OR E>F)
{
If (A==1)
Call ADD (A+B*-C, -D- -F*-G)
Else
W [I, J] = X [I, J] + Y[W[k, L]] + Z[I+J]
U [I, J, K] = V [I, J, K, L]
}
Expectations:
1. Find out all the tokens generated by lexical analyzer.
2. Perform the syntax tree for last two operations (elsestatements) used in program.
3. Perform the semantic analysis over the syntax.
4. Evaluate intermediate code (3-address code) for the given loop.
5. Optimize the code in terms of memory allocation.
-
8/8/2019 System Dp Mukesh 2003
3/13
Solution of the design problem
1. Find out all the tokens generated by lexical analyzer.
1.lexical analyzer is basically used for the analysis of keywords,identifiers using a
table called symbol maintenance table. Its classification depends on the source
language that we used for the implementation of all the items produced by the
lexical analyzer.
Analyzer is basically used for the creation or development of the descriptor i.e.
lexical. Token basically consist of two parts i.e. class code and number in class.
Class code is used to address the class to which a lexical unit belongs. Number in
the class is the entry number of the lexical unit in the relevant table.
According to the ques. All elements are divided into following categories:-
a) Identifier-it basically uses id as a symbol or token class code for theidentifier. Numbers can be used as per our requirements.
so ,here are all the identifiers and all the corresponding tokens used for them.
-
8/8/2019 System Dp Mukesh 2003
4/13
SR NO TOKEN
I.A id#1
II.B id#2
III.C id#3
IV.D id#4
V .E id#5
VI.F id#6
VII. G id#7
VIII .W id#8
IX .X id#9
X. Y id#10
XII . Z id#11
XIII .U id#12
XIV .V id#13
XV . I id#14
XVI .J id#15
XVII.K id#16
XVII.L id#17
-
8/8/2019 System Dp Mukesh 2003
5/13
b).keywords-it is a name that has a special meaning and functionality. It can be
also used to represent symbol or as an operator. In this the class code is a key.
SR NO TOKEN
I .if key#1
II .while key#2
III . ADD key#3
IV. else key#4
3.operator-their main purpose is to compare between the various variables and
identifiers .they are represented by the symbol (op)
SR NO TOKEN
I . < op#1
II. > op#2
III. AND op#3
IV. OR op#4
V. + op#5
VI. - op#6
VII. * op#7
VIII.== op#8
4.special symbol-these are special notations like array parameter etcthe class
code is (ss)
-
8/8/2019 System Dp Mukesh 2003
6/13
SR NO TOKEN
I.( ss#1
II.) ss#2
III .[ ss#3
IV.] ss#4
V., ss#5
Expectation2:-Perform the syntax tree for last two operations (else
statements) used in program.
-
8/8/2019 System Dp Mukesh 2003
7/13
Solution 2. A)
-
8/8/2019 System Dp Mukesh 2003
8/13
B)
Expectation3:- Perform the semantic analysis over the syntax.
Solution of 3:- it is an perception that semantic analysis is always depends on thesyntactic but it is not so it also provides the info. About the syntax provided. Main
purpose of semantic is to do the generation of the intermediate code from the
source language. And it is also used to define an action that has to be implemented
on the source statement. Semantic analysis not only determines the meaning of the
parse tree that has been created by the help of syntax analysis but it also adds
-
8/8/2019 System Dp Mukesh 2003
9/13
info. To the the tables .these tables and sequences results in the production of
their in the analysis phase.
Node no. Semantic action
L.place = i
(1) E.place = i
(2) Elist.array = X
Elist.place= i
Elist.dim=1
(3) L.place = j
(4) E.place= j
(5) M=2 , t1 (newtemp) t1=i*d2
Elist.place = t1 t1=t1+j
Elist.dim =m
Elist.array = X
(6) L.place = t2 (newtemp) t2= C(X)L.offset = t3 (newtemp) t3=t1*w
(8) L.place = i
(9) E.place = i
(10) L.place=j
(11) E.place = j
(12) t4 (newtemp ) t4 = i+j
(13) Elist.array = Y
Elist.place = t4
Elist.dim =1
-
8/8/2019 System Dp Mukesh 2003
10/13
(14) L.place = k
(15) E.place = k
(16) m=2 , t5 (newtemp) t5=t4*d4
Elist.array = Y
Elist.place = t5 t5=t5 + k
Elist.dim=2
(17) t6 (newtemp) t6= C(Y)
t7 (newtemp) t7= t5*w
(18) t8 (newtemp) t8=t6[t7]
(19) L.place = z
L.offset= NULL
(20) L.place= z
(21) t9 (newtemp) t9 = t8 + z
(22) t2[t3] := t9
Expectation4:- Evaluate intermediate code (3-address code) for the given
loop.
Solution of 4. it is an activity performed by the analyzer for the generation of the
code .but to d this first we have to understand the architecture of the target
language. It helps in understanding of the complete knowledge of all the
instructions and addressing modes that has been used in the target computer.
We have three steps to generate the code:-
1.allocation of the intermediate result in the memory which leads to aseparate process.
2. specification of the instruction that has to be used for type conversion
of operations.
-
8/8/2019 System Dp Mukesh 2003
11/13
3.specification of the all the specification modes that has been used for the
variable accessing.
Code generation is as follows:-
1) Compare ( (id # 3)
2) Compare (>) (id # 4) to (id # 5) ( id # 6)
3) We are giving comparison , again them, we get ( id # 2)
4) Assignment operator (=) , with (id # 1) to (id # 20) which -( id # 10)
5) ( - ) -minus sign ; negative (id # 2),which is giving another id ( id # 2)
6) Now comes , multiplication, (id # 11) with (id # 4)(id #11)
7) Next step is of addition (id # 1) with (id # 11) which will give (id # 11)
8) Again there is unary operation (negation) from (id # 12) after (id # 18)
9) After this , it is repetition of unary operation (negation) from (id # 14) to
(id # 13)
10) After this we multiply (id # 12) with (id # 13) giving (id # 13)
11) Unary operation negation (id # 15) (id # 12)
12) After doing all operations , we substrate (id # 12) from (id # 13)
13) Addition of (id # 21 ) with (id # 22) gives (id # 17)
14) Addition of (id # 25) gives (id # 16) (id # 17)
15) Store the result in (id # 19)
16) Store (id # 19) in (id # 15) which is the result.
Expectation 5:-.optimize the code in terms of memory allocation.
Solution 5:-Its main concern is about proper usage or proper management of the
memory by the analyzer and to divide memory in order to get memory optimization.
-
8/8/2019 System Dp Mukesh 2003
12/13
Memory optimization can be done in different ways but before doing that we must
know how to allocate the memory and use it in our code.
So first we will concern about the memory allocation and after that steps to
reduce the memory used by us.
Code optimization is as follows:
Symbol type address
A real 2001
C real 2002
temp1 real 2003
B real 2004
D real 2005
temp2 real 2006
E real 2007
F real 2008
temp3 real 2009
temp4 real 2010
temp5 real 2011
temp6 real 2012
temp7 real 2013
b1 real 2014
w[i,j] array 2015
x[i,j] array 2025
temp9 real 2026
-
8/8/2019 System Dp Mukesh 2003
13/13
w[i,j] array 2027
x[i,j] array 2037
above we can see that we have used memory for variable, constant or any
operator. There are several Steps to reduce the memory that has been used for
temp allocation but we concern only about the result only.
Steps are as follows:-
1.first,we have to remove all the memory that has been used for temp allocation in
between the calculations.
2.secondly,memeory optimization has to be done for all the operators we have used
like :,and,or,etc.
3.thirdly,identifying and collecting garbage value due to program execution and
compilation.
4.fourthly,by using dynamic memory instead of the of the static memory for the
allocations of variables.