Sri Vidya College of Engineering and Technology Question Bank
Sri Vidya College of Engineering and Technology Question Bank
Sri Vidya College of Engineering and Technology Question Bank
4. What is a regular expression? State the rules, which define regular expression?
Regular expression is a method to describe regular language
Rules:
1) ε-is a regular expression that denotes {ε} that is the set containing the empty
string
2) If a is a symbol in ∑,then a is a regular expression that denotes {a}
3) Suppose r and s are regular expressions denoting the languages L(r ) and L(s)
Then,
a) (r )/(s) is a regular expression denoting L(r) U L(s).
b) (r )(s) is a regular expression denoting L(r )L(s)
c) (r )* is a regular expression denoting L(r)*.
d) (r) is a regular expression denoting L(r ).
7. What is recognizer?
Recognizers are machines. These are the machines which accept the strings belonging to
certain
language. If the valid strings of such language are accepted by the machine then it is said that
the corresponding language is accepted by that machine, otherwise it is rejected.
STUDENTSFOCUS.COM
SRI VIDYA COLLEGE OF ENGINEERING AND TECHNOLOGY QUESTION BANK
Union - L U M ={s | s is in L or s is in M}
Concatenation – LM ={st | s is in L and t is in M}
Kleene Closure – L* (zero or more concatenations of L)
Positive Closure – L+ ( one or more concatenations of L)
13. Mention the various notational shorthands for representing regular expressions.
Hierarchical analysis is one in which the tokens are grouped hierarchically into nested
collections with collective meaning. Also termed as Parsing.
STUDENTSFOCUS.COM
SRI VIDYA COLLEGE OF ENGINEERING AND TECHNOLOGY QUESTION BANK
Semantic analysis is one in which certain checks are performed to ensure that
components of a program fit together meaningfully. Mainly performs type checking.
16 MARKS
Main Task: Take a token sequence from the scanner and verify that it is a syntactically correct
program.
Secondary Tasks:
Process declarations and set up symbol table information accordingly, in preparation for
semantic analysis.
Construct a syntax tree in preparation for intermediate code generation.
An NFA is similar to a DFA but it also permits multiple transitions over the same character and
transitions over . In the case of multiple transitions from a state over the same character, when
we are at this state and we read this character, we have more than one choice; the NFA succeeds
if at least one of these choices succeeds. The transition doesn't consume any input characters,
so you may jump to another state for free.
Clearly DFAs are a subset of NFAs. But it turns out that DFAs and NFAs have the same
expressive power. The problem is that when converting a NFA to a DFA we may get an
exponential blowup in the number of states.
We will first learn how to convert a RE into a NFA. This is the easy part. There are only 5 rules,
one for each type of RE:
STUDENTSFOCUS.COM
SRI VIDYA COLLEGE OF ENGINEERING AND TECHNOLOGY QUESTION BANK
As it can been shown inductively, the above rules construct NFAs with only one final state. For
example, the third rule indicates that, to construct the NFA for the RE AB, we construct the
NFAs for A and B, which are represented as two boxes with one start state and one final state for
each box. Then the NFA for AB is constructed by connecting the final state of A to the start state
of B using an empty transition.
The next step is to convert a NFA to a DFA (called subset construction). Suppose that you assign
a number to each NFA state. The DFA states generated by subset construction have sets of
numbers, instead of just one number. For example, a DFA state may have been assigned the set
{5, 6, 8}. This indicates that arriving to the state labeled {5, 6, 8} in the DFA is the same as
arriving to the state 5, the state 6, or the state 8 in the NFA when parsing the same input. (Recall
that a particular input sequence when parsed by a DFA, leads to a unique state, while when
parsed by a NFA it may lead to multiple states.)
First we need to handle transitions that lead to other states for free (without consuming any
input). These are the transitions. We define the closure of a NFA node as the set of all the
nodes reachable by this node using zero, one, or more transitions. For example, The closure of
node 1 in the left figure below
STUDENTSFOCUS.COM
SRI VIDYA COLLEGE OF ENGINEERING AND TECHNOLOGY QUESTION BANK
is the set {1, 2}. The start state of the constructed DFA is labeled by the closure of the NFA start
state. For every DFA state labeled by some set {s1,..., sn} and for every character c in the
language alphabet, you find all the states reachable by s1, s2, ..., or sn using c arrows and you
union together the closures of these nodes. If this set is not the label of any other node in the
DFA constructed so far, you create a new DFA node with this label. For example, node {1, 2} in
the DFA above has an arrow to a {3, 4, 5} for the character a since the NFA node 3 can be
reached by 1 on a and nodes 4 and 5 can be reached by 2. The b arrow for node {1, 2} goes to
the error node which is associated with an empty set of NFA nodes.
The following NFA recognizes (a| b)*(abb | a+b), even though it wasn't constructed with the
above RE-to-NFA rules. It has the following DFA:
STUDENTSFOCUS.COM