sheet1 -...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS
160:
Practice
Sheet
1
(do
not
turn
in)
 
 1) Regular
Expressions
and
DFAs:

The
following
description
of
a
regular
 language
below,
please
circle
the
one
regular
expression
that
best
 describes
it
AND
the
one
DFA
that
best
describes
it
(you
should
have
one
 RE
and
one
DFA
circled).

 
 
 The
set
of
strings
over
the
alphabet
 {a,b}
in
which
there
are
an
even
 number
of
a’s.

Example
strings
that
 should
be
accepted
include:
ε,
aa,
baa,
 bb,
abbbabb;
example
strings
that
 should
NOT
be
accepted
include:
a,
 babb,
aaa
 a. (b)*(a(b)*a(b)*)* b. (b)*(ab*a)* c. ((a|b)*a(a|b)*a(a|b)*)* d. (a|b)*(aa)(a|b)* 
 
 
 
 2) Give
the
regular
expression
for
the
following
languages
over
Σ =
{0,1}
 a. All
strings
containing
exactly
one
0
 b. All
strings
where
each
0
is
followed
by
at
least
one
1
 c. All
strings
containing
no
more
than
three
0s
 d. All
strings
not
ending
in
01
 e. All
strings
with
an
odd
number
of
0s

 f. All
strings
with
an
odd
number
of
0s
and
an
odd
number
of
1s

 g. All
strings
that
contain
101
 h. All
strings
that
do
not
contain
101
 
 3) Consider
a
messed
up
programming
language
where
you
can
only
have
 two
characters:
x
and
o.
Here
is
the
scanner
for
this
language:
 
 /x*ooo/
 
 {return
B;}
 /o(x|o)?ooxoox/

{return
C;}
 /o+/

 
 {return
S;}
 /x(x|o)x/


 {return
U;}
 
 a. What
would
the
scanner
return
for:
ooooooo
 b. What
would
the
scanner
return
for:
xxxoxooxooxooxooo
 c. What
would
the
scanner
return
for:
oooooxoooooo
 
 4) Write
a
regular
expression
for
numerical
constants
which
conform
to
the
 following
list
of
restrictions:
 
 a. At
least
one
digit
precedes
the
decimal
point
 b. The
decimal
point
is
optional,
but
if
present,
it
is
followed
by
at
 least
one
digit.
 c. Except
as
demanded
by
(a)
and
(b),
leading
and
trailing
zero
digits
 are
not
permitted.
 
 
 
 
 ...
View Full Document

This note was uploaded on 12/27/2011 for the course CMPSC 162 taught by Professor Franklin during the Fall '09 term at UCSB.

Ask a homework question - tutors are online