Professional Documents
Culture Documents
18CS61 SSC II IA Question Bank
18CS61 SSC II IA Question Bank
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.
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.
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.