Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

18CS61 SSC II IA QUESTION BANK

QUESTIONS FROM MODULE 2 -- CHAPTER 1 INTRODUCTION TO COMPILERS


1. Explain different types of Language Processors.
Expected Answer:
Explanation for Compiler, Interpreter, and Hybrid Translator with diagram for each.
2. Explain the working of various phases of the compiler.
OR
Explain the Structure of the Compiler with the diagram.
Expected Answer:
Brief Explanation of each Phase of compiler and Diagram
3. Give the output of each phase for the following C statement: Some C statement will be given
in the Exam.
Expected Answer:
Write the output of each phase of the compiler for the given C Statement
4 Analyze the working of various phases of the compiler with the help of following C
statement:
Expected Answer:
Brief Explanation of each Phase of compiler and Diagram
Write the output of each phase of the compiler for the given C Statement
5. Differentiate between Compiler and Interpreter
Expected Answer:
Any Eight Valid Technical difference points.
Students may collect the difference points and show to me before the Test for verification purpose.
QUESTIONS FROM MODULE 2 -- CHAPTER 3 LEXICAL ANALYSIS
1. Why analysis portion is divided into lexical analysis and syntax analysis (parsing)?
Expected Answer:
The Reasons for the above question and Explanations of each reason points
2. What is the role of Lexical analyzer? Explain with diagram.
OR
Explain the interaction between Lexical Analyzer and Parser with a diagram.
Expected Answer:
Diagram:

Explanation Required.
3. Explain the terms Token, Pattern and Lexeme with the suitable example.
Expected Answer:
Explanation of each term specified in the question with suitable example
4. Show the Tokens, Pattern and Lexeme in the following example. (Some Example will be given)
Expected Answer:
Show Tokens, Patterns and Lexemes for the given example.
5. Describe Lexical Errors with an example. What are the different error recovery actions?
Expected Answer:
Lexical errors: It is hard for a lexical analyzer to tell, without the help of other components,
that there is a source-code error.
For instance,
fi ( a = = f(x))
A lexical analyzer cannot tell whether fi is a misspelling of the keyword if or an undeclared
function identifier.

Different types of Error recovery Actions are:


❑ Delete successive characters from the remaining input, until the lexical analyzer can
find a well-formed token at the beginning of what input is left.
❑ Delete one character from the remaining input
❑ Insert a missing character into the remaining input
❑ Replace a character by another character
❑ Transpose two adjacent character

Explanations are required.


6. Explain the Buffer Pairs mechanism of lexical analysis phase.
Expected Answer:
Working of Input Buffering with Buffer Pairs method of lexical analyzer
7. Explain the Sentinels mechanism of lexical analysis phase.
Expected Answer:
Working of Input Buffering with Sentinels method of lexical analyzer
8. Develop an algorithm to demonstrate the working of sentinels.
Expected Answer:
Write the Algorithm for Sentinels.:
Switch(*forward++)
{
case eof:
if (forward is at end of first buffer)
{ reload second buffer;
forward = beginning of second buffer;
}
else if (forward is at end of second buffer)
{ reload first buffer;
forward = beginning of first buffer;
}
else /* eof within a buffer marks the end of input terminate lexical analysis*/
break;
case for the other characters
}

9. Discuss the various operations of the languages with suitable example.


OR
Some problem related to Operations on Languages will be given
Sample Problem:
Let L1 is a language containing the alphabet set {a, b, c, d} and L2 is the Language containing
the alphabet set {1, 2, 3, 4}
What is the various alphabet sets in the new language formed by the following operations
on the languages L1 and L2?
(i) L1 U L2 (ii) L1 L2 (iii) L13 Including Empty string
Expected Answer:
Various Operations on Languages:

10. Express the Algebraic Laws of regular expression.


Expected Answer:

11 Define Regular Definition. Give the regular definition for recognizing the following Tokens:
In examination, anything may be given.
Example: (i) Digit, (ii) unsigned Integer (iii) Letter
(iii) Identifier (iv) Unsigned Floating-Point Number
(v) Floating-Point Number etc…
(Note to all students: Default case of Number is Unsigned Number)
But not restricted to the above list.
Similarly, we may ask you by using extensions.
By default, students using extensions is not asked in the question, then by default, students may
use extension to write regular definition or may not use extensions to write regular definition.
Expected Answer:
Formal Definition of Regular Definition:
If ∑ is an alphabet of basic symbols, then A regular definition is a sequence of the
definitions of the form:
d1 → r1
d2 → r2
....
dn → rn
Where:
■ Each di is a new symbol, not in ∑ and not the same as any other of the d’s
■ Each ri is a Regular Expression over the alphabet
∑ U {d1, d2, d3,………di-1}

Regular Definition for recognizing the Given Tokens: Refer my PPT for regular definition
of some sample examples. Similarly, the students should write the appropriate definitions
for given example. If the Question asked is “with Extensions” then students should use
with extensions. By default, students may use extensions or may not, students wish.
12. What is transition diagram? Summarize various conventions used in the transition diagram.
Expected Answer:
Definition of Transition Diagram:
■ An intermediate step in the construction of lexical analyzer is conversion of patterns
into stylized flowcharts called “transition diagrams”
■ Transition diagrams have a collection of node or circles called states.
■ Each state represents a condition that could occur during the process of scanning the
input, looking for a lexeme that matches one of several patterns.

Various Conventions used in the Transition Diagram:


Certain states are said to be accepting state or final state - indicate that a lexeme has been
found.
Action to be taken ---return a token & attribute value to the parser and attach the action
to the accepting state.
If it is necessary to retract the forward pointer one position, we place a * at the final
(accepting) state. In our example, it is never necessary to retract forward by more than one
position, but if it were, we could attach any number of * to the accepting state.
One state is “start” state or initial state indicated by an edge labeled “start”.

13. Develop the algorithm to implement the transition diagram to recognize _____
Expected Answer:
Students should write the Regular Definition for recognising the given example. Based on
this regular definition, students should write Transition Diagram. Based on this Transition
Diagram, Students should write the algorithm.
Without Regular Definition, Transition Diagram is invalid. Without Transition
Diagram, Algorithm becomes invalid.
14. Apply regular definition and hence transition diagram to recognize the following tokens:
Any tokens may be asked in the exam. Here is sample to ask
(i) Relational Operator (in Pascal) (ii) identifier
(iii) Number (Unsigned Floating-Point Number) (iv) White Space
etc…
Expected Answer:
Students should write the Regular Definition for recognising the given example. Based on
this regular definition, students should write Transition Diagram.
Without Regular Definition, Transition Diagram is invalid.
QUESTIONS FROM MODULE 4 – LEX-YACC
1. Give the Roles of each execution phase of LEX and YACC Program. Why YACC Program must
be compiled with -d option?
OR
Explain how you run lex yacc programs.
Expected Answer:
% lex chl-n.1
% yacc -d chl-m.y
% cc -c 1ex.yy.c y.tab.c
% cc -0 example-m.n 1ex.yy.o y.tab.0 -ll
Explanation of the above steps is required.
2. Explain the Lexer-Parser Communication.
When you use a lex scanner and a yacc parser together, the parser is the higher-level routine. It
calls the lexer yylex() whenever it needs a token from the input. The lexer then scans through the
input recognizing tokens. As soon as it finds a token of interest to the parser, it returns to the
parser, returning the token’s code as the value of yylex().
Not all tokens are of interest to the parser—in most programming languages the parser does not
want to hear about comments and whitespace, for example. For these ignored tokens, the lexer does
not return so that it can continue to the next token without bothering the parser.
The return statements show that yylex() acts like a coroutine. Each time the parser calls it, it takes
up processing at the exact point it left off. This allows us to examine and operate upon the input
stream incrementally.
Little more explanation required about compilation of LEX and YACC Programs.
3. Write a Lex Program: (Any Program from the LAB or equivalent may be asked)
Expected Answer:
Write the Program for given problem. (LAB Program)
4. Write a YACC Program to ______________ (Any Program from LAB or equivalent may be asked)
Write the Program
Expected Answer:
Write the Program for given problem. (LAB Program)
5. Explain the various fields of the LEX and YACC Programming Language.
Expected Answer:
LEX PROGRAMMING LANGUAGE:
There are three sections in the LEX Programming Language:
Definition Section, Rules Section, and Subroutine Section.
Explanation of each section is required.

YACC PROGRAMMING LANGUAGE:


There are three sections in the LEX Programming Language:
Definition Section, Rules Section, and Subroutine Section.
Explanation of each section is required.

You might also like