CSC173: Project 1
-
Finite automata are simple computing “devices” that recognize patterns, as seen in classand in the textbook.For this project, you must implement a framework that you (or any programmer) can useto define and execute automata in order to recognize patterns. The framework comesdirectly from the formal model of automata.Using your framework, you should be able to define and execute any finite automatonfor any pattern that can be recognized by a finite automaton.Note: The project is not about writing programs that recognize specific patterns. Yes,you will use your framework in a program that creates and executes a number of differentautomata (details below). But the specific patterns are not the point of the project. Infact, I recommend that you not even think about the specific patterns as you design andimplement the framework.Process not product.Once you have the framework, for each pattern that you need to recognize, you must:• Design the automaton for the pattern, probably by drawing its graph on your whiteboard or on paper.• Translate the graph into the elements of the formal model of automata, in particularthe transition function/table that comes from the edges of its graph.• Write a function that uses your framework to create and return an instance of anautomaton with that definition.• Demonstrate your framework by running such an instance interactively, asking theuser for input strings, running the automaton on the strings, and printing the results.The rest of this document gives you the specific requirements as well some suggestionsfor how to get started. Read the requirements and instructions carefully. You must meetthe requirements to get the points.If you are new to C and haven’t yet done Homework 0.0, you should do that now
Part 1: Deterministic Finite Automata (50%)Implement a framework for defining and executing deterministic finite automata (DFAs),as follows:• You must define a DFA data structure and whatever functions you need to create,inspect and configure instances (constructor, accessors, and mutators).• For each required DFA (see below), you must have a function that creates andreturns a properly-configured DFA. For example, for a DFA that accepts stringscontaining “abc”:DFA* DFA_for_contains_abc()• You must have a function that can execute any DFA on a given input string andreturn true or false (accept or reject). For example:bool DFA_run(DFA* dfa, char* input)• You must have a function that can run any DFA in a “Read-Eval-Print Loop” (REPL):prompting for user input, running the DFA on the input, and printing the result. Forexample:void DFA_repl(DFA* dfa)• Your main function must run instances of each of the required DFAs in a REPLone after the other, printing informative messages.You must demonstrate your DFA framework on all of the following languages:(a) Exactly the string “dfa” (without the quotes)(b) Strings that start with the sequence “cat” (without the quotes).(c) Strings containing exactly two 2’s (and perhaps other characters also).(d) Binary input (input consisting of only 0’s and 1’s) where there are an even numberof 0’s and an odd number of 1’s. (If you are not sure whether zero is even or odd,please got to study session.)
Part 2: Nondeterministic Finite Automata (30%)Implement a framework (or extend your previous framework) to allow the definition andexecution of non-deterministic finite automata (NFAs), as follows:• You must define an NFA data structure and whatever functions you need to create,inspect and configure instances (constructor, accessors, and mutators).• For each required NFA (see below), you must have a function that creates andreturns a properly-configured NFA. For example, for an NFA that accepts stringsending with “ing”:NFA* NFA_for_ends_with_ing()• You must have a function that can execute any NFA on a given input string andreturn true or false (accept or reject). For example:bool NFA_run(NFA* nfa, char* input)• You must have a function that can run any NFA in a REPL, prompting for userinput, running the NFA on the input, and printing the result. For example:void NFA_repl(NFA* nfa)• Your main function must run each of the required NFAs in a REPL one after theother, printing informative messages.You must demonstrate your NFA framework on all of the following languages:(a) Strings ending in ked, such as “liked” and “sacked”, but not, for example,“shakedown”.(b) Strings containing ath, such as “athletic”, “bather”, and “path”.(c) Strings that have more than one o, f, or r, or more than two c’s or n’s, or more thanthree e’s. In this automaton, acceptance means that the input string is definitelynot a partial anagram of conference, because it has too many of some letter.Note that this automaton does not accept all strings that are not anagrams ofconference. See FOCS Ex. 10.6 and Fig. 10.14 for a similar automaton and thestory behind it. The automaton in the book accepts when the criterion is met, butyou will probably need to do something slightly different to accept an entire stringmeeting the criterion
Part 3: Equivalence of DFAs and NFAs (20%)Implement a translator function that takes an instance of an NFA (any NFA) as its onlyparameter and returns a new instance of a DFA that is equivalent to the original NFA(accepts the same language), using the standard algorithm as seen in class and in thetextbook. For example:DFA* NFA_to_DFA(NFA* nfa)Demonstrate your NFA to DFA translator by using the first two NFAs from Part 2, translating them to DFAs, printing out how many states are in the resulting DFA, and runningit on user input as described below. That is, you will have three functions that produceNFAs for Part 2 of the project. For the first two of those, pass the NFA that they return toyour converter and run the resulting DFA using your DFA REPL function.You should also try to convert the third NFA from Part 2. You might want to think about(a) the complexity of the Subset Construction itself, and (b) the implementation of thedata structures used by your translator, such as lists and sets. You can’t beat (a), seeFOCS pp. 550–552, but you could profile your code and try to do better on (b).FWIW: My implementation using IntHashSet on an M1 MacBook Pro with 32GBof RAM took about ten minutes to convert the “Washington”-based NFA from FOCSEx. 10.6
咨询 Alpha 小助手,获取更多课业帮助