Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Final Exam / Fall 2020 (Paper Duration 24 hours)

(Online Short Questions Based Paper)

Course No.: CS-636 Course Title: Compiler Construction


Total Marks: 20 Date of Exams: 10/02/2021
Degree: BSCS Semester: 5th Section: A + B
Marks
Q. No. 1 2 3 4 5 6 7 8 9 10 Obtained/
Total Marks
Marks
Obtaine
d
Total Obtained Marks in Words:
Name of the Teacher:
Who taught the course: Signature of Teacher / Examiner:

To be filled by Student

Registration No.: Name:

(THEORETICAL EXAMINATION)

Answer the following questions.


Q. No. 1: Discuss the Role of Look-Ahead technique in Parsing. (02)

A practical technique for computing look ahead for an LR(0) parser, that progressively attempts single-
symbol, multi-symbol, and arbitrary look ahead . The technique determines the amount of look ahead
required, and the user is spared the task of guessing it.

The class of context-free grammars defined by our technique is a subset of the LR-regular grammars; we
show that unlike LR-regular, the problem of determining whether an arbitrary grammar is in the class, is
decidable. When restricted to k-symbol look ahead, the technique

has the power of LALR(k) parsers. It has been successfully used to resolve multi-symbol look ahead
conflicts in grammars for FORTRAN, Ada, C, COBOL, and PL/I, and its performance compares favorably with
that of two well-known, commercially available parser generators.
Q. 2: Handle played a vital role to Reduce the production? Discuss with example. (02)

Answer:
A bottom-up parser operates by repeatedly locating handles on the frontier of the partial parse tree and
performing reductions that they specify.
Handle operates by repeatedly locating handles on the frontier of the partial parse tree and performing
reductions that they specify.
Example:
A → β

b is the right-hand side of some production A → b, and 2. A → b is one step in right-most derivation
of input stream.

Q. No. 3: Why Bottom-up Parser is called Shift-Reduce Parser? You are required to explain the use of
Shift and Reduce action with example. (02)

ANSWER:

Shift-reduce parsing uses two unique steps for bottom-up parsing. These steps are known as shift-step and
reduce-step. Shift step: The shift step refers to the advancement of the input pointer to the next input
symbol, which is called the shifted symbol. This symbol is pushed onto the stack.

Shift-reduce parsing is a process of reducing a string to the start symbol of a grammar.


Shift reduce parsing uses a stack to hold the grammar and an input tape to hold the string.
Shift reduce parsing
Sift reduce parsing performs the two actions: shift and reduce. That's why it is known as shift reduces
parsing.
At the shift action, the current symbol in the input string is pushed to a stack.
At each reduction, the symbols will be replaced by the non-terminals. The symbol is the right side of the
production and the non-terminal is the left side of the production.
Q.No.4: Elaborate, step wise, following picture in context of building Parser by YACC and LEX. (04)

Answer:
A file named as expr.y , contained Grammar, worked as an inputof YACC, an automated tool.
YACC produces two files named as y.tab.c and y.tab.h. Y.tab.c is a C file and Y.lab.h is a header
File. Y.tab.h works as an input filefo LEX, second tool. Second input file of LEX named as expr.l
Is also present. After input LEX generates output file named as lex.yy.c which is a C file. At the
end both output files such as y.tab.c and lex.yy.c of the LEX are given to compiler, and compiler
generates the executable file named as expr.exe. Which is basically the intermediate form of
the process.

Q.No.5: What is wrong with this Program? Perform Syntactic and Semantic Analysis of this code. (05)

void first(int a, int b)


{ .... }
void second() {
int f[3],g[0],h,i,j,k;
char* p;
first(h, i, “ab”);
k = f*i+j;
h = g[17];
p = 10;
}
Answer:
ERRORS:
All are semantic errors.
1: Dimension of g is 0,
Index is 17
2: wrong number of args to function file.

3: f is an array:
Used without index.

4: 10 is not a character string.


It is only a single character.
Q.No.6. Build Parse Tree for -101 Signed Binary Number. (05)

Answer:
Draw on Page and paste its snapshot here

You might also like