Beruflich Dokumente
Kultur Dokumente
ASSIGMENT NO. 1
MAIN ISSUE :- To develop a Lexical Analyzer one should possess the basic
knowledge of the followings.
(1)
push tokens & its attributes
Read Character
Lexical
Input Analyzer Parser
Push back character
(2)
Token Val
LINKING:- After developing all modules we need to link all them modules properly.
Use link option Given by ‘C’ language.
COMPILER CONSTRUCTION (TCS502)
Problems :-
Que1. Write a grammar that recognize c variable declaration made up of following
keywords.
Int, char, long, float, signed, unsigned
Que2. Write a grammar that recognize c variable declaration made up only of following legal
combinations of following keywords.
Int, char, long, float, signed, unsigned
Que3. Write a grammar (and a recursive-decent compiler for that grammer) that translate an
English description of a c variable in to c style variable declaration.
REFERENCES:-
(1) Aho,Ullman, Sethi ------ Compiler Construction.
(2) Allen I.Holub-------------Compiler Construction.
COMPILER CONSTRUCTION (TCS502)
ASSIGMENT NO. 2
FOR Eg.:- Consider the following rules to describe a possible syntax for the block in a
Pascal like language-
CFG as follows:
G=(T, N, S, P)
Where T(G) is a finite, new empty set of terminals and tokens.
Where N(G) is a finite, new empty set of non terminals and tokens.
Problems :-
Que1. Show a step-by-step left most derivation of the following expressions
1+2* ((3+4) +5) +6
Que2. The following regular expressions recognizes a series of binary digits with pattern
000. use to terminate the series.
(0/1)*000
Que3. Write a regular expressions that can recognize all possible integer constant in c all of
the following should be recognized :
0x89ab 0123 45 ‘z’ ‘\t’ ‘\012’
EXPLANATION:- A Grammar whose parsing table has no multiple defined entities is said
to be LL(1). The first “L” in LL(1) stands for scanning the input from the left to right the
second “L” for producing a leftmost derivation and “1” for using one input symbol of look
ahead at each step to make parsing action decision.
Problems :-
Que1. Is the following grammar in LL(1)? why or why not? Or if it is not convert it in to
LL(1) .
E=E+T/ T
T=T*F/ F
F=(E)/ id
Que2. Generate the LL(1) parsing table for the following grammar:
S=iCtSS’/ a
S’=eS/ e(null)
C=b
Que3. Find out the First and Follows of both Que1 and Que2.
Problems :-
Quadruples
Problems :-
(a) a+b+c*d/e+f
(b) p+q*r+s*t
(c) a*r+u*n+I+m*a
EXPLANATION:-To avoid the entering temporary names into symbol table be might refer
to a temporary value by the position of statement that computes it. It consist three fields
op ,arg1,arg2.
a:=b*-c + b*-c
op arg1 arg2
(0) uniminus c
(1) * b (0)
(2) uniminus c
(3) * b (2)
(4) + (1) (3)
(5) assign a (4)
Problems :-
Que1. Implement the following expressions into quadruples using C language.
(d) a+b+c*d/e+f
(e) p+q*r+s*t
(f) a*r+u*n+I+m*a
EXPLANATION: using the facilities given by the block structured language C and
using the mechanisms provided by c like parameter gassings through several
methods, implement the following problems and justify your answers .
The language may be Pascal also. Also use the scope rules provided by the
C/PASCAL language.
program a(input/output);
procedure b(u,v,x,y:integer);
var a: record a,b:integer end;
b: record b,a:integer end;
Begin
With a do begin a:=u;b:=v end;
with b do begin a:=x;b:=y end;
writeln(a.a,a.b,b.a,b.b)
end;
begin
b(1,2,3,4)
end.
Problems :-
Que1. What is printed by the program assuming call-by-value,
Que5. Discuss the above parameters passing methods in detail in your answer
sheet using at least 5 examples of each one.
ASSIGMENT NO. 8
EXPLANATION: using the facilities given by the block structured language C and
using the mechanisms provided by c like parameter gassings through several
methods, implement the following problems and justify your answers .
The language may be Pascal also. Also use the scope rules provided by the
C/PASCAL language.
program main(input,output);
procedure p(x,y,z);
begin
y:=y+1;
z:=z+x;
end;
begin
a:=2;
b:=3;
p(a+b,a,a);
print a
end.
Problems :-
Que1. When a procedure is passed as a parameter in a lexically scoped language,
its non-local environment can be passed using an access link. Give an algorithm to
determine this link.
Que2. The three kinds of environments that could be associated with a procedure
passed as a parameter are illustrated by the Pascal program in Fig. given
below.The lexical, passing and activation environments of such a procedure consists
of the bindings of identifiers at the point at which the procedure is defined, passed as
a parameter, and activated; respectively. Consider function f, passed as a parameter
on line 11.
Using the lexical, parsing, and activation environments for f, non-local m on line 8 is
in the scope of the declarations of m on lines 6, 10, and 3, respectively.
Que3. Discuss about the Dangling References along with appropriate example.
OBJECTIVE: - Using the facilities provided by the C Language Justify Your answers.
EXPLANATION:Using the Knowledge of the compilation process and its all phases try to
find out the best optimal solutions for the given problems .it includes the Syntax Directed
Translation Schemes ,Run time Storage Administration and Basic Parsing Techniques as
Discussed in the Aho,Ullman of compiler construction book.
Try to implement these modules in C language IF Possible
Problems :-
Q1: Translate the arithmetic expression a*-( b+c) into
a) a syntax tree
b) postfix notation
c) three-address code