What code goes in #TODOs?
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
What code goes in #TODOs?

Transcribed Image Text:# TODO: This is your class for modeling NFAS/DFAS! Some is already stubbed out for you.
class NFA:
"""A class for NFAS that can be constructed from a Regex"""
def _init_(self, r = None):
"""Constructs an empty-language NFA when r==None,
or constructs an NFA from the provided Regex object."""
self.r = r #s Save a reference to the regex itself
if r == None:
# If no Regex instance is provided: the empty language
start = State()
self.Q =
{start}
self.Sigma =
set()
self.s = start
self.F = set()
self.delta = set()
elif isinstance(r, EpsilonRegex):
pass # TODO: the epsilon language, base form (Hint: look in regex.py)
elif isinstance(r, StarRegex):
pass # TODO: handle derived form star
elif isinstance(r, SeqRegex):
pass # TODO: handle derived form juxtaposition/sequencing
elif isinstance(r, DisjRegex):
# Note how this is exactly the Disjunction construction
# we saw in the slides for converting RE -> NFA
nfað = NFA(r.r@)
nfa1 = NFA(r.r1)
start = State()
end = State()
# TODO: what about self.Q?
self.Sigma = nfa®.Sigma | nfa1.Sigma
# TODO: what about self.s?
self.F = {end}
# Explanation: below, min
nice for selecting an arbitrary
# element; as we maintain as an invariant that self.F is
# a singleton for the duration of NFA construction, this works well
# (may not be the case for DFAS; also note: empty string is epsilon)
self.delta = ({(start,
', nfa®.s), (start,
"", nfa1.s),
(min(nfa®.F), "", end), (min(nfa1.F), "", end)}
| nfað.delta | nfa1.delta)
elif isinstance(r, CharRegex):
pass # TODO: handle base form (Hint: look in regex.py)
else:
raise "NFA must be constructed from a Regex (or None)."
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps

Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education