CS2 Practical 2 CS2Ah

Size: px
Start display at page:

Download "CS2 Practical 2 CS2Ah"

Transcription

1 CS2 Practical 2 Finite automata This practical is based on material in the language processing thread. The practical is made up of two parts. Part A consists of four paper and pencil exercises, designed to test your understanding of the lecture material. Your answers to this part should be submitted to your tutor, by the deadline below, using whatever mechanism your tutor arranges for receiving submissions. For part B you must write and submit part of a Java application, which can be used to convert NFAs into equivalent DFAs and to simulate the execution of DFAs. Your answer to this part should be submitted electronically, using the handin command, as described below. Both parts of the practical are worth 50% of the mark. Note that there are no dependencies between parts A and B of the practical. You are strongly encouraged to start on both parts of the practical as soon as possible. In particular, it is not advisable to leave part B until you have completed part A. This practical has been issued on Monday 5th November, and the deadline for submitting answers to both parts is 5pm on Monday 19th November. Late submissions will only be accepted in the case of genuine mitigating circumstances, for example illness, and with the agreement of the course organiser. Your marked work for this practical will be returned to you by your tutor during the tutorial in the week starting Monday 3rd December. Remember that you will need at least a grade C (i.e. at least 50%) in your final CS2 mark to proceed to any of the Computer Science or Software Engineering single or joint honours courses. You should also bear in mind the guidelines on plagiarism, which can be found via a link on the CS2 Web page. Resources The practical handout refers to various files. webpage These can all be found on the 1

2 Part A [50] 1. (a) Design a DFA that recognises the language L over the alphabet {a, b, c} consisting of all strings that contain the substring ababc, i.e., the language L = { xababcy x, y {a, b, c} }. Draw a picture of this DFA and write out the formal specification of the DFA including its transition table. (b) Design a DFA that accepts precisely those strings over {a, b, c} that are not contained in the language L defined in (a), i.e., a DFA that recognises the language Draw a picture of this DFA. L { = { x {a, b, c} x L }. 2. Which of the following languages over the alphabet {0, 1, 2} are regular? L 1 = { 0 n 112 2n n N }, L 2 = {(01122) n n N}, L 3 = { 0 m 112 2n m, n N }. Justify your answers, either by providing a DFA, an NFA, or a regular expression for the language to show that it is regular or by proving that the language is not regular. Use the Pumping Lemma to prove that a language is not regular. 3. (a) Give regular expressions for the following two languages over the alphabet {0, 1}: L 1 = { x {0, 1} x contains an even number of 0s }, L 2 = { x {0, 1} x contains an even number of 0s and an odd number of 1s }. Hint: To find regular expressions, you may first want to design a DFA recognising the languages and then convert them to regular expressions using the method described in Lecture Note 4. (b) Construct an NFA with ε-transitions that recognises the language L(R) of the following regular expression R over the alphabet {a, b}: 4. For a language L Σ, let R = (a + b(ab a) b) SH(L) = { y Σ x Σ x = y and xy L }, the language consisting of the second halves of all strings of even length in L. For example, if L = {ε, a, abba, aba, aaba, aa} then SH(L) = {ε, ba, a}. Show that if L is regular then SH(L) is also regular. (Note: This problem is quite difficult, it is recommended that you complete the rest of the practical before attempting to solve it.) 2

3 Problem 1 is worth 10% of your mark, Problems 2 and 3 are worth 15% each, and Problem 4 is worth 10%. Submit your answers to Part A following the instructions given to you by your tutor. You must submit before the deadline of 5pm on Monday 19th November. Part B [50] The directory for this practical contains a partially implemented Java application, Prac2, for simulating finite automata. Your task is to complete this application and apply it to a pattern matching problem. The files and Java classes The directory contains the following files: A file FA.java, which contains the code of an abstract class FA implementing most of the features of finite automata. States of finite automata are represented by String objects, and letters of the alphabet by chars. The most important public methods of the class are: the constructor method public FA(), which creates an empty automaton object, the constructor method public FA(String filename), which reads an automaton from a file (the format of this file is explained below), a number of public methods for modifying an existing automaton object, for example a method public void addstate(string q) that adds a state to an automaton, or a method public void setstart- State(String q) that defines the start state, a number of methods for obtaining information about an existing automaton object, for example a method public boolean isstate(string q) that test if string q represents a state of the automaton, a method public String tostring() that writes the whole automaton into a string in the same format as the file used in the constructor. For details, look at the source code. Files DFA.java and NFA.java, which contain the code of two subclasses DFA and NFA of FA implementing the remaining features of DFAs and NFAs, respectively. The reason for this design is that DFAs and NFAs share most of their basic functionality, but have different types of transition functions. So most features related to the transitions have to be implemented separately. Most notably, the method public String getnextstate(string q,char c) 3

4 of the class DFA returns an object of type String representing the next state of a DFA when reading c in state q, and the method public LLSet getnextstates(string q,char c) of the class NFA returns an object of type LLSet representing the set of possible next states of an NFA when reading c in state q. A file LLSet.java, which contains the implementation of a class LLSet that can be used to represent sets. The implementation is based on linked lists; technically, LLSet is a subclass of class LinkedList. The important property of sets, as opposed to simple linked lists, is that no object can occur twice in a set. We use LLSets to represent sets of next states in an NFA. A file FAGui.java which contains the code of the graphical user interface. A file Prac2.java which contains the main method of the application. Files RunDFA.java and NFA2DFA.java in which you are supposed to implement the following three methods: public static boolean accepts(dfa M,String s), public static LinkedList extract(dfa M,String filename), public static DFA convert(nfa N). A file TokExample.java which contains a class illustrating the use of the Java class StreamTokenizer. Example files nfa1, nfa1a, dfa1, dfa2, which contain a few example automata. You should begin by copying all the files to a new directory in your own filespace (and remember to read-protect the directory). 1 You can then compile the, currently incomplete, application: javac Prac2.java To execute it type java Prac2. 1 Look at the CS2 Practical 1 handout if you don t remember how to do these things. 4

5 q0 q1 q2 q3 q4 Figure 1: The NFA stored in file nfa1 The graphical user interface Starting the application produces a GUI containing an input field, a result field, and six buttons with the following functionalities: Load NFA: Asks you to enter a filename in the input field, then loads the NFA specified in this file and displays it in the result field. Load DFA: Same for DFA instead of NFA. Save DFA: Asks you to enter a filename in the input field and then saves the currently loaded DFA into a file with that name. Save Result: Asks you to enter a filename in the input field and then saves the current content of the result field into a file with that name. Convert: Converts the NFA currently loaded into a DFA accepting the same language and displays this DFA in the result field. This functionality is not yet implemented. Run DFA: Asks you to enter a string in the input field and tests if the DFA currently loaded accepts this string. This functionality is not yet implemented. Extract: Asks you to enter a filename in the input field and displays all words in the file with this name that are accepted by the DFA currently loaded in the result window. This functionality is not yet implemented. Quit: Quits the application. The file format The format in which finite automata are stored for this application is largely selfexplanatory. Open the file nfa1. It contains a description of the automaton in Figure 1. Since it is often tedious to write out the full alphabet, it is allowed to represent intervals of consecutive letters using a dash, as in A-Z. This is allowed both in the alphabet and transitions section of the file. Open the file nfa1a to see how this allows a more compact representation of the automaton in Figure 1. 5

6 In general, a file representing a DFA or an NFA consists of: A field enclosed by tags <states> and </states> which contains strings representing the states of the automaton, separated by whitespaces. Strings representing states may consist of all printable ASCII symbols except (blank), or more precisely, of all ASCII symbols whose code is between 33 and 126. A field enclosed by tags <alphabet> and </alphabet> which contains either single characters (whose ASCII code is between 33 and 126) representing letters of the alphabet of the automaton or expressions of the form c 1 -c 2, where c 1 and c 2 are characters, representing all characters whose ASCII code is between that of c 1 and c 2. Note that no whitespaces are allowed between the dash and the enclosing letters. A field enclosed by tags <startstate> and </startstate> which contains a string representing the start state of the automaton. A field enclosed by tags <finalstates> and </finalstates> which contains strings representing the final states of the automaton, separated by whitespaces. A field enclosed by tags <transitions> and </transitions> which contains the transitions of the automaton. Transitions are represented by lines q1 c q2 saying that if the automaton is in state q1 and reads character c it may proceed to state q2. Similarly to the alphabet section, transitions may also be represented in the form q1 c 1 -c 2 q2 saying that if the automaton is in state q1 and reads any character c whose ASCII code is between that of c 1 and c 2 it may proceed to state q2. As a final example, look at the file dfa1, which contains a DFA accepting the same language as the NFA in nfa1. Your Tasks 1. Implement the method public static boolean accepts(dfa M,String s) of the class RunDFA (in the file RunDFA.java). Given an object M of type DFA and an object s of type String, this method is supposed to return true if the DFA represented by M accepts the string s and false otherwise. 2. Implement the method public static LinkedList extract(dfa M,String filename) 6

7 of the class RunDFA (in the file RunDFA.java). Given an object M of type DFA, representing a DFA whose alphabet is {A,..., Z, a,..., z}, and an object filename of type String, this method is supposed to read the textfile specified by filename, split it into words that only contain letters (i.e., characters between A and Z and between a and z ), and return a linked list consisting of all strings accepted by the DFA represented by M. 3. Implement the method public static DFA convert(nfa N) of the class NFA2DFA (in the file NFA2DFA.java). Given an object N of type NFA, this method is supposed to return an object M of type DFA such that the NFA represented by N and the DFA represented by M recognise the same language. 4. Specify an NFA N that accepts the language L consisting of all strings over the alphabet Σ = {A, B,..., Z, a, b,..., z} that contain the letters a, b, c in any order. (Thus for example, tobacco and subtraction are in L, and char is not.) Write N into a file abc-nfa in the format specified above. Use the convert function to transform it into an equivalent DFA, and save this DFA in a file abc-dfa. Then use the extract function to extract all words that contain the letters a,b,c from the file /usr/dict/words. Save the result in a file abc-words. When implementing the methods, it is advisable to split the tasks into subtask handled by separate methods (which you can implement as private methods of the respective classes). It is important that you comment your code appropriately. A complete solution consists of the (modified) files RunDFA.java and NFA2DFA.java and the files abc-nfa and abc-words. Ensure that all your files contain your name, address, tutor s name, and submission date. Submit your solution using the commands handin 2 RunDFA.java handin 2 NFA2DFA.java handin 2 abc-nfa handin 2 abc-words You may do this any time after 5pm on Monday 12th November, up until the deadline of 5pm on Monday 19th November. Bear in mind that the computer labs are likely to be busy just before the practical deadline. It is up to you to ensure that you plan your work in order to submit in time. (Note that if you modify your code once you have submitted then you can resubmit and your earlier submission will be overwritten.) 7

8 Assessment Assessment for part B will include: marks assigned on the basis of how your program behaves on a test suite, and also marks for good programming style (including commenting the code). To get reasonable marks: You must submit code that compiles. You should test your code yourself on a number of suitably chosen test cases to ensure that it works. You must submit following the instructions above. (I.e. you must give the files the correct filenames, and you must use the handin command.) Tasks 1, 2, and 4 are worth 10% of your mark each and tasks 3 is worth 20%. Hints After you have implemented task 1, test the accept functionality by running the example DFAs, for instance those in the files dfa1 and dfa2, on a couple of example strings. To process the input file for task 2, you may want to use a StreamTokenizer. The file TokExample.java gives an example of how this can be done. Also recall CS1 Lecture Notes 25 and 27. Consult the Java API documentation to learn more about StreamTokenizers. For task 3, use the method described in Lecture Note 3. Recall that in this method, the states of the DFA you obtain are sets of states of the original NFA. Sets can be represented as objects of the class LLSet (defined in the file LLSet.java). Since the states of an NFA are strings, you have to turn the LLSets into strings using the method LLSet.toString(). Familiarise yourselves with the Java class java.util.linkedlist and its subclass LLSet. Recall CS1 Lecture Note 26 on Lists and Iterators and also look at the Java API documentation. Note that we are exclusively dealing with NFAs without ε-transitions. This simplifies the conversion to DFAs, because in this case for every state q a of an NFA and every letter a of its alphabet, the set s with q s (in the notation of Lecture Note 3) is simply the q, a-entry in the transition table, that is, the set returned by the method getnextstates of the class NFA. To see the result of an example conversion, consider the file nfa1 describing an NFA and the file dfa1 showing the result of converting this NFA into a DFA recognising the same language. 8

9 To test whether your conversion algorithm works properly, you can (but do not have to) use the method public boolean isdeterministic() of the class NFA. Do not make changes to any classes except RunDFA and DFA2NFA, or your submitted coded may not work properly when we compile it and test it with the original classes. Martin Grohe 9

CS2 Practical 6 CS2Bh 24 January 2005

CS2 Practical 6 CS2Bh 24 January 2005 CS2 Practical 6 Data Structures for Dictionaries This practical is based on material of the Algorithms and Data Structures thread. It has two parts: Part A, worth 40 marks, consists of four pen-and-paper

More information

CS2 Practical 1 CS2A 22/09/2004

CS2 Practical 1 CS2A 22/09/2004 CS2 Practical 1 Basic Java Programming The purpose of this practical is to re-enforce your Java programming abilities. The practical is based on material covered in CS1. It consists of ten simple programming

More information

CS103 Handout 14 Winter February 8, 2013 Problem Set 5

CS103 Handout 14 Winter February 8, 2013 Problem Set 5 CS103 Handout 14 Winter 2012-2013 February 8, 2013 Problem Set 5 This fifth problem set explores the regular languages, their properties, and their limits. This will be your first foray into computability

More information

Last lecture CMSC330. This lecture. Finite Automata: States. Finite Automata. Implementing Regular Expressions. Languages. Regular expressions

Last lecture CMSC330. This lecture. Finite Automata: States. Finite Automata. Implementing Regular Expressions. Languages. Regular expressions Last lecture CMSC330 Finite Automata Languages Sets of strings Operations on languages Regular expressions Constants Operators Precedence 1 2 Finite automata States Transitions Examples Types This lecture

More information

1. (10 points) Draw the state diagram of the DFA that recognizes the language over Σ = {0, 1}

1. (10 points) Draw the state diagram of the DFA that recognizes the language over Σ = {0, 1} CSE 5 Homework 2 Due: Monday October 6, 27 Instructions Upload a single file to Gradescope for each group. should be on each page of the submission. All group members names and PIDs Your assignments in

More information

School of Informatics, University of Edinburgh

School of Informatics, University of Edinburgh CS1Bh Practical 1 Words and Sentences This is an individual practical exercise which requires you to submit some Java programs and some text files for assessment. A system which measures software similarity

More information

Formal Definition of Computation. Formal Definition of Computation p.1/28

Formal Definition of Computation. Formal Definition of Computation p.1/28 Formal Definition of Computation Formal Definition of Computation p.1/28 Computation model The model of computation considered so far is the work performed by a finite automaton Formal Definition of Computation

More information

CS103 Handout 13 Fall 2012 May 4, 2012 Problem Set 5

CS103 Handout 13 Fall 2012 May 4, 2012 Problem Set 5 CS103 Handout 13 Fall 2012 May 4, 2012 Problem Set 5 This fifth problem set explores the regular languages, their properties, and their limits. This will be your first foray into computability theory,

More information

CS52 - Assignment 10

CS52 - Assignment 10 CS52 - Assignment 10 Due Wednesday 12/9 at 7:00pm https://xkcd.com/205/ Important Notice Assignments 9 and 10 are due at the same time. This is to give you maximum flexibility in scheduling during the

More information

I have read and understand all of the instructions below, and I will obey the Academic Honor Code.

I have read and understand all of the instructions below, and I will obey the Academic Honor Code. Midterm Exam CS 341-451: Foundations of Computer Science II Fall 2014, elearning section Prof. Marvin K. Nakayama Print family (or last) name: Print given (or first) name: I have read and understand all

More information

Theory of Computation Dr. Weiss Extra Practice Exam Solutions

Theory of Computation Dr. Weiss Extra Practice Exam Solutions Name: of 7 Theory of Computation Dr. Weiss Extra Practice Exam Solutions Directions: Answer the questions as well as you can. Partial credit will be given, so show your work where appropriate. Try to be

More information

Context-Free Grammars

Context-Free Grammars Context-Free Grammars Describing Languages We've seen two models for the regular languages: Finite automata accept precisely the strings in the language. Regular expressions describe precisely the strings

More information

CS/ECE 374 Fall Homework 1. Due Tuesday, September 6, 2016 at 8pm

CS/ECE 374 Fall Homework 1. Due Tuesday, September 6, 2016 at 8pm CSECE 374 Fall 2016 Homework 1 Due Tuesday, September 6, 2016 at 8pm Starting with this homework, groups of up to three people can submit joint solutions. Each problem should be submitted by exactly one

More information

CS5371 Theory of Computation. Lecture 8: Automata Theory VI (PDA, PDA = CFG)

CS5371 Theory of Computation. Lecture 8: Automata Theory VI (PDA, PDA = CFG) CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG) Objectives Introduce Pushdown Automaton (PDA) Show that PDA = CFG In terms of descriptive power Pushdown Automaton (PDA) Roughly

More information

JNTUWORLD. Code No: R

JNTUWORLD. Code No: R Code No: R09220504 R09 SET-1 B.Tech II Year - II Semester Examinations, April-May, 2012 FORMAL LANGUAGES AND AUTOMATA THEORY (Computer Science and Engineering) Time: 3 hours Max. Marks: 75 Answer any five

More information

School of Informatics, University of Edinburgh

School of Informatics, University of Edinburgh CS1Ah Practical 4 Motorway Madness This is an individual practical exercise which requires you to submit some files electronically. A system which measures software similarity will be used to compare all

More information

CS103 Handout 42 Spring 2017 May 31, 2017 Practice Final Exam 1

CS103 Handout 42 Spring 2017 May 31, 2017 Practice Final Exam 1 CS103 Handout 42 Spring 2017 May 31, 2017 Practice Final Exam 1 We strongly recommend that you work through this exam under realistic conditions rather than just flipping through the problems and seeing

More information

Important Project Dates

Important Project Dates Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2002 Handout 4 Project Overview Wednesday, September 4 This is an overview of the course project

More information

ASSIGNMENT 5 Objects, Files, and a Music Player

ASSIGNMENT 5 Objects, Files, and a Music Player ASSIGNMENT 5 Objects, Files, and a Music Player COMP-202A, Fall 2009, All Sections Due: Thursday, December 3, 2009 (23:55) You MUST do this assignment individually and, unless otherwise specified, you

More information

R10 SET a) Construct a DFA that accepts an identifier of a C programming language. b) Differentiate between NFA and DFA?

R10 SET a) Construct a DFA that accepts an identifier of a C programming language. b) Differentiate between NFA and DFA? R1 SET - 1 1. a) Construct a DFA that accepts an identifier of a C programming language. b) Differentiate between NFA and DFA? 2. a) Design a DFA that accepts the language over = {, 1} of all strings that

More information

Chapter Seven: Regular Expressions

Chapter Seven: Regular Expressions Chapter Seven: Regular Expressions Regular Expressions We have seen that DFAs and NFAs have equal definitional power. It turns out that regular expressions also have exactly that same definitional power:

More information

14.1 Encoding for different models of computation

14.1 Encoding for different models of computation Lecture 14 Decidable languages In the previous lecture we discussed some examples of encoding schemes, through which various objects can be represented by strings over a given alphabet. We will begin this

More information

CSSE2002/7023 The University of Queensland

CSSE2002/7023 The University of Queensland CSSE2002 / CSSE7023 Semester 1, 2016 Assignment 1 Goal: The goal of this assignment is to gain practical experience with data abstraction, unit testing and using the Java class libraries (the Java 8 SE

More information

Lexical Analysis. Lecture 2-4

Lexical Analysis. Lecture 2-4 Lexical Analysis Lecture 2-4 Notes by G. Necula, with additions by P. Hilfinger Prof. Hilfinger CS 164 Lecture 2 1 Administrivia Moving to 60 Evans on Wednesday HW1 available Pyth manual available on line.

More information

CMPE 4003 Formal Languages & Automata Theory Project Due May 15, 2010.

CMPE 4003 Formal Languages & Automata Theory Project Due May 15, 2010. CMPE 4003 Formal Languages & Automata Theory Project Due May 15, 2010. Regular Expression Engine (This document contains 5 pages. Read carefully all parts of this document.) Introduction In this project,

More information

Compiler Construction LECTURE # 3

Compiler Construction LECTURE # 3 Compiler Construction LECTURE # 3 The Course Course Code: CS-4141 Course Title: Compiler Construction Instructor: JAWAD AHMAD Email Address: jawadahmad@uoslahore.edu.pk Web Address: http://csandituoslahore.weebly.com/cc.html

More information

Department of Computer Science. COS 122 Operating Systems. Practical 3. Due: 22:00 PM

Department of Computer Science. COS 122 Operating Systems. Practical 3. Due: 22:00 PM Department of Computer Science COS 122 Operating Systems Practical 3 Due: 2018-09-13 @ 22:00 PM August 30, 2018 PLAGIARISM POLICY UNIVERSITY OF PRETORIA The Department of Computer Science considers plagiarism

More information

Lexical Analysis. Lecture 3. January 10, 2018

Lexical Analysis. Lecture 3. January 10, 2018 Lexical Analysis Lecture 3 January 10, 2018 Announcements PA1c due tonight at 11:50pm! Don t forget about PA1, the Cool implementation! Use Monday s lecture, the video guides and Cool examples if you re

More information

CS 337 Project 1: Minimum-Weight Binary Search Trees

CS 337 Project 1: Minimum-Weight Binary Search Trees CS 337 Project 1: Minimum-Weight Binary Search Trees September 6, 2006 1 Preliminaries Let X denote a set of keys drawn from some totally ordered universe U, such as the set of all integers, or the set

More information

ASSIGNMENT 5 Objects, Files, and More Garage Management

ASSIGNMENT 5 Objects, Files, and More Garage Management ASSIGNMENT 5 Objects, Files, and More Garage Management COMP-202B, Winter 2010, All Sections Due: Wednesday, April 14, 2009 (23:55) You MUST do this assignment individually and, unless otherwise specified,

More information

Compiler Construction

Compiler Construction Compiler Construction Exercises 1 Review of some Topics in Formal Languages 1. (a) Prove that two words x, y commute (i.e., satisfy xy = yx) if and only if there exists a word w such that x = w m, y =

More information

CSE Theory of Computing Fall 2017 Project 2-Finite Automata

CSE Theory of Computing Fall 2017 Project 2-Finite Automata CSE 30151 Theory of Computing Fall 2017 Project 2-Finite Automata Version 1: Sept. 27, 2017 1 Overview The goal of this project is to have each student understand at a deep level the functioning of a finite

More information

Homework 1 Due Tuesday, January 30, 2018 at 8pm

Homework 1 Due Tuesday, January 30, 2018 at 8pm CSECE 374 A Spring 2018 Homework 1 Due Tuesday, January 30, 2018 at 8pm Starting with this homework, groups of up to three people can submit joint solutions. Each problem should be submitted by exactly

More information

CS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer

CS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer CS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer Assigned: Thursday, September 16, 2004 Due: Tuesday, September 28, 2004, at 11:59pm September 16, 2004 1 Introduction Overview In this

More information

NFAs and Myhill-Nerode. CS154 Chris Pollett Feb. 22, 2006.

NFAs and Myhill-Nerode. CS154 Chris Pollett Feb. 22, 2006. NFAs and Myhill-Nerode CS154 Chris Pollett Feb. 22, 2006. Outline Bonus Questions Equivalence with Finite Automata Myhill-Nerode Theorem. Bonus Questions These questions are open to anybody. I will only

More information

Automating Construction of Lexers

Automating Construction of Lexers Automating Construction of Lexers Regular Expression to Programs Not all regular expressions are simple. How can we write a lexer for (a*b aaa)? Tokenizing aaaab Vs aaaaaa Regular Expression Finite state

More information

CPSC 121: Models of Computation Assignment #5

CPSC 121: Models of Computation Assignment #5 CPSC 2: Models of Computation Assignment #5 Due: Monday, November 27, 27 at 4:pm Total Marks: 27 Submission Instructions-- read carefully We strongly recommend that assignments be done in groups of 2.

More information

Lexical Analysis - 2

Lexical Analysis - 2 Lexical Analysis - 2 More regular expressions Finite Automata NFAs and DFAs Scanners JLex - a scanner generator 1 Regular Expressions in JLex Symbol - Meaning. Matches a single character (not newline)

More information

CS103 Handout 16 Winter February 15, 2013 Problem Set 6

CS103 Handout 16 Winter February 15, 2013 Problem Set 6 CS103 Handout 16 Winter 2012-2013 February 15, 2013 Problem Set 6 How much firepower do context-free languages have? What are their limits? And just how awesome are PDAs? In this problem set, you'll get

More information

CS402 Theory of Automata Solved Subjective From Midterm Papers. MIDTERM SPRING 2012 CS402 Theory of Automata

CS402 Theory of Automata Solved Subjective From Midterm Papers. MIDTERM SPRING 2012 CS402 Theory of Automata Solved Subjective From Midterm Papers Dec 07,2012 MC100401285 Moaaz.pk@gmail.com Mc100401285@gmail.com PSMD01 MIDTERM SPRING 2012 Q. Point of Kleen Theory. Answer:- (Page 25) 1. If a language can be accepted

More information

Skyup's Media. PART-B 2) Construct a Mealy machine which is equivalent to the Moore machine given in table.

Skyup's Media. PART-B 2) Construct a Mealy machine which is equivalent to the Moore machine given in table. Code No: XXXXX JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY, HYDERABAD B.Tech II Year I Semester Examinations (Common to CSE and IT) Note: This question paper contains two parts A and B. Part A is compulsory

More information

CS2 Language Processing note 3

CS2 Language Processing note 3 CS2 Language Processing note 3 CS2Ah 5..4 CS2 Language Processing note 3 Nondeterministic finite automata In this lecture we look at nondeterministic finite automata and prove the Conversion Theorem, which

More information

Lexical Analysis. Lecture 3-4

Lexical Analysis. Lecture 3-4 Lexical Analysis Lecture 3-4 Notes by G. Necula, with additions by P. Hilfinger Prof. Hilfinger CS 164 Lecture 3-4 1 Administrivia I suggest you start looking at Python (see link on class home page). Please

More information

Announcements! P1 part 1 due next Tuesday P1 part 2 due next Friday

Announcements! P1 part 1 due next Tuesday P1 part 2 due next Friday Announcements! P1 part 1 due next Tuesday P1 part 2 due next Friday 1 Finite-state machines CS 536 Last time! A compiler is a recognizer of language S (Source) a translator from S to T (Target) a program

More information

CSE Theory of Computing Spring 2018 Project 2-Finite Automata

CSE Theory of Computing Spring 2018 Project 2-Finite Automata CSE 30151 Theory of Computing Spring 2018 Project 2-Finite Automata Version 2 Contents 1 Overview 2 1.1 Updates................................................ 2 2 Valid Options 2 2.1 Project Options............................................

More information

CS 403 Compiler Construction Lecture 3 Lexical Analysis [Based on Chapter 1, 2, 3 of Aho2]

CS 403 Compiler Construction Lecture 3 Lexical Analysis [Based on Chapter 1, 2, 3 of Aho2] CS 403 Compiler Construction Lecture 3 Lexical Analysis [Based on Chapter 1, 2, 3 of Aho2] 1 What is Lexical Analysis? First step of a compiler. Reads/scans/identify the characters in the program and groups

More information

University of Nevada, Las Vegas Computer Science 456/656 Fall 2016

University of Nevada, Las Vegas Computer Science 456/656 Fall 2016 University of Nevada, Las Vegas Computer Science 456/656 Fall 2016 The entire examination is 925 points. The real final will be much shorter. Name: No books, notes, scratch paper, or calculators. Use pen

More information

Understanding and Exploring Memory Hierarchies

Understanding and Exploring Memory Hierarchies Understanding and Exploring Memory Hierarchies Issued : Thursday 27th January 2011 Due : Friday 11th March 2011 at 4.00pm (at the ITO) This assignment represents the total practical component of the Computer

More information

CSE Theory of Computing Spring 2018 Project 2-Finite Automata

CSE Theory of Computing Spring 2018 Project 2-Finite Automata CSE 30151 Theory of Computing Spring 2018 Project 2-Finite Automata Version 1 Contents 1 Overview 2 2 Valid Options 2 2.1 Project Options.................................. 2 2.2 Platform Options.................................

More information

Worksheet 3: Predictive Text Entry

Worksheet 3: Predictive Text Entry Worksheet 3: Predictive Text Entry MSc & ICY Software Workshop, Spring term 2015-16 Seyyed Shah and Uday Reddy Assigned: Tuesday 2 February Intermediate deadline : parts 1 and 2, Tuesday 9th February,

More information

Models of Computation II: Grammars and Pushdown Automata

Models of Computation II: Grammars and Pushdown Automata Models of Computation II: Grammars and Pushdown Automata COMP1600 / COMP6260 Dirk Pattinson Australian National University Semester 2, 2018 Catch Up / Drop in Lab Session 1 Monday 1100-1200 at Room 2.41

More information

ECS 120 Lesson 7 Regular Expressions, Pt. 1

ECS 120 Lesson 7 Regular Expressions, Pt. 1 ECS 120 Lesson 7 Regular Expressions, Pt. 1 Oliver Kreylos Friday, April 13th, 2001 1 Outline Thus far, we have been discussing one way to specify a (regular) language: Giving a machine that reads a word

More information

CSE P 501 Exam 8/5/04

CSE P 501 Exam 8/5/04 Name There are 7 questions worth a total of 65 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. You may refer to the following references: Course

More information

Lexical Analysis. Chapter 2

Lexical Analysis. Chapter 2 Lexical Analysis Chapter 2 1 Outline Informal sketch of lexical analysis Identifies tokens in input string Issues in lexical analysis Lookahead Ambiguities Specifying lexers Regular expressions Examples

More information

Multiple Choice Questions

Multiple Choice Questions Techno India Batanagar Computer Science and Engineering Model Questions Subject Name: Formal Language and Automata Theory Subject Code: CS 402 Multiple Choice Questions 1. The basic limitation of an FSM

More information

QUESTION BANK. Formal Languages and Automata Theory(10CS56)

QUESTION BANK. Formal Languages and Automata Theory(10CS56) QUESTION BANK Formal Languages and Automata Theory(10CS56) Chapter 1 1. Define the following terms & explain with examples. i) Grammar ii) Language 2. Mention the difference between DFA, NFA and εnfa.

More information

Regular Languages (14 points) Solution: Problem 1 (6 points) Minimize the following automaton M. Show that the resulting DFA is minimal.

Regular Languages (14 points) Solution: Problem 1 (6 points) Minimize the following automaton M. Show that the resulting DFA is minimal. Regular Languages (14 points) Problem 1 (6 points) inimize the following automaton Show that the resulting DFA is minimal. Solution: We apply the State Reduction by Set Partitioning algorithm (särskiljandealgoritmen)

More information

Theory Bridge Exam Example Questions Version of June 6, 2008

Theory Bridge Exam Example Questions Version of June 6, 2008 Theory Bridge Exam Example Questions Version of June 6, 2008 This is a collection of sample theory bridge exam questions. This is just to get some idea of the format of the bridge exam and the level of

More information

Implementation of Lexical Analysis. Lecture 4

Implementation of Lexical Analysis. Lecture 4 Implementation of Lexical Analysis Lecture 4 1 Tips on Building Large Systems KISS (Keep It Simple, Stupid!) Don t optimize prematurely Design systems that can be tested It is easier to modify a working

More information

CMPSCI 250: Introduction to Computation. Lecture 20: Deterministic and Nondeterministic Finite Automata David Mix Barrington 16 April 2013

CMPSCI 250: Introduction to Computation. Lecture 20: Deterministic and Nondeterministic Finite Automata David Mix Barrington 16 April 2013 CMPSCI 250: Introduction to Computation Lecture 20: Deterministic and Nondeterministic Finite Automata David Mix Barrington 16 April 2013 Deterministic and Nondeterministic Finite Automata Deterministic

More information

1. [5 points each] True or False. If the question is currently open, write O or Open.

1. [5 points each] True or False. If the question is currently open, write O or Open. University of Nevada, Las Vegas Computer Science 456/656 Spring 2018 Practice for the Final on May 9, 2018 The entire examination is 775 points. The real final will be much shorter. Name: No books, notes,

More information

2010: Compilers REVIEW: REGULAR EXPRESSIONS HOW TO USE REGULAR EXPRESSIONS

2010: Compilers REVIEW: REGULAR EXPRESSIONS HOW TO USE REGULAR EXPRESSIONS 2010: Compilers Lexical Analysis: Finite State Automata Dr. Licia Capra UCL/CS REVIEW: REGULAR EXPRESSIONS a Character in A Empty string R S Alternation (either R or S) RS Concatenation (R followed by

More information

(Refer Slide Time: 0:19)

(Refer Slide Time: 0:19) Theory of Computation. Professor somenath Biswas. Department of Computer Science & Engineering. Indian Institute of Technology, Kanpur. Lecture-15. Decision Problems for Regular Languages. (Refer Slide

More information

Lexical Analysis. Implementation: Finite Automata

Lexical Analysis. Implementation: Finite Automata Lexical Analysis Implementation: Finite Automata Outline Specifying lexical structure using regular expressions Finite automata Deterministic Finite Automata (DFAs) Non-deterministic Finite Automata (NFAs)

More information

CS 536 Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 5

CS 536 Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 5 CS 536 Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 5 CS 536 Spring 2015 1 Multi Character Lookahead We may allow finite automata to look beyond the next input character.

More information

3.15: Applications of Finite Automata and Regular Expressions. Representing Character Sets and Files

3.15: Applications of Finite Automata and Regular Expressions. Representing Character Sets and Files 3.15: Applications of Finite Automata and Regular Expressions In this section we consider three applications of the material from Chapter 3: searching for regular expressions in files; lexical analysis;

More information

CS 215 Fundamentals of Programming II Fall 2017 Project 7. Morse Code. 30 points. Out: November 20, 2017 Due: December 4, 2017 (Monday) a n m

CS 215 Fundamentals of Programming II Fall 2017 Project 7. Morse Code. 30 points. Out: November 20, 2017 Due: December 4, 2017 (Monday) a n m CS 215 Fundamentals of Programming II Fall 2017 Project 7 30 points Out: November 20, 2017 Due: December 4, 2017 (Monday) This project is to build a Morse code tree and use it to encode and decode messages.

More information

Announcements. Prelude (2) Prelude (1) Data Structures and Information Systems Part 1: Data Structures. Lecture 6: Lists.

Announcements. Prelude (2) Prelude (1) Data Structures and Information Systems Part 1: Data Structures. Lecture 6: Lists. Announcements MODULE WEB-SITE: http://www.csc.liv.ac.uk/ michele/teaching/comp102/comp102.html FIRST ASSIGNMENT DEADLINE: Wednesday, February 1st, 14.30, LAB 7 Boxes (late submissions to be left in the

More information

Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit.

Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit. Com S 227 Fall 2017 Miniassignment 1 50 points Due Date: Monday, October 16, 11:59 pm (midnight) Late deadline (25% penalty): Tuesday, October 17, 11:59 pm General information This assignment is to be

More information

CSE 105 THEORY OF COMPUTATION

CSE 105 THEORY OF COMPUTATION CSE 105 THEORY OF COMPUTATION Spring 2018 http://cseweb.ucsd.edu/classes/sp18/cse105-ab/ Today's learning goals Sipser Section 2.2 Define push-down automata informally and formally Trace the computation

More information

CS Lecture 2. The Front End. Lecture 2 Lexical Analysis

CS Lecture 2. The Front End. Lecture 2 Lexical Analysis CS 1622 Lecture 2 Lexical Analysis CS 1622 Lecture 2 1 Lecture 2 Review of last lecture and finish up overview The first compiler phase: lexical analysis Reading: Chapter 2 in text (by 1/18) CS 1622 Lecture

More information

UNIT I PART A PART B

UNIT I PART A PART B OXFORD ENGINEERING COLLEGE (NAAC ACCREDITED WITH B GRADE) DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING LIST OF QUESTIONS YEAR/SEM: III/V STAFF NAME: Dr. Sangeetha Senthilkumar SUB.CODE: CS6503 SUB.NAME:

More information

Concepts Introduced in Chapter 3. Lexical Analysis. Lexical Analysis Terms. Attributes for Tokens

Concepts Introduced in Chapter 3. Lexical Analysis. Lexical Analysis Terms. Attributes for Tokens Concepts Introduced in Chapter 3 Lexical Analysis Regular Expressions (REs) Nondeterministic Finite Automata (NFA) Converting an RE to an NFA Deterministic Finite Automatic (DFA) Lexical Analysis Why separate

More information

Project 1: Implementation of the Stack ADT and Its Application

Project 1: Implementation of the Stack ADT and Its Application Project 1: Implementation of the Stack ADT and Its Application Dr. Hasmik Gharibyan Deadlines: submit your files via handin by midnight (end of the day) on Thursday, 10/08/15. Late submission: submit your

More information

CS2 Algorithms and Data Structures Note 10. Depth-First Search and Topological Sorting

CS2 Algorithms and Data Structures Note 10. Depth-First Search and Topological Sorting CS2 Algorithms and Data Structures Note 10 Depth-First Search and Topological Sorting In this lecture, we will analyse the running time of DFS and discuss a few applications. 10.1 A recursive implementation

More information

Dr. D.M. Akbar Hussain

Dr. D.M. Akbar Hussain 1 2 Compiler Construction F6S Lecture - 2 1 3 4 Compiler Construction F6S Lecture - 2 2 5 #include.. #include main() { char in; in = getch ( ); if ( isalpha (in) ) in = getch ( ); else error (); while

More information

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou COMP-421 Compiler Design Presented by Dr Ioanna Dionysiou Administrative! [ALSU03] Chapter 3 - Lexical Analysis Sections 3.1-3.4, 3.6-3.7! Reading for next time [ALSU03] Chapter 3 Copyright (c) 2010 Ioanna

More information

Formal Languages and Automata

Formal Languages and Automata Mobile Computing and Software Engineering p. 1/3 Formal Languages and Automata Chapter 3 Regular languages and Regular Grammars Chuan-Ming Liu cmliu@csie.ntut.edu.tw Department of Computer Science and

More information

Lecture 18 Regular Expressions

Lecture 18 Regular Expressions Lecture 18 Regular Expressions In this lecture Background Text processing languages Pattern searches with grep Formal Languages and regular expressions Finite State Machines Regular Expression Grammer

More information

CS103 Handout 35 Spring 2017 May 19, 2017 Problem Set 7

CS103 Handout 35 Spring 2017 May 19, 2017 Problem Set 7 CS103 Handout 35 Spring 2017 May 19, 2017 Problem Set 7 What can you do with regular expressions? What are the limits of regular languages? In this problem set, you'll explore the answers to these questions

More information

ASSIGNMENT 5 Data Structures, Files, Exceptions, and To-Do Lists

ASSIGNMENT 5 Data Structures, Files, Exceptions, and To-Do Lists ASSIGNMENT 5 Data Structures, Files, Exceptions, and To-Do Lists COMP-202B, Winter 2009, All Sections Due: Tuesday, April 14, 2009 (23:55) You MUST do this assignment individually and, unless otherwise

More information

Actually talking about Turing machines this time

Actually talking about Turing machines this time Actually talking about Turing machines this time 10/25/17 (Using slides adapted from the book) Administrivia HW due now (Pumping lemma for context-free languages) HW due Friday (Building TMs) Exam 2 out

More information

Introduction to Lexical Analysis

Introduction to Lexical Analysis Introduction to Lexical Analysis Outline Informal sketch of lexical analysis Identifies tokens in input string Issues in lexical analysis Lookahead Ambiguities Specifying lexical analyzers (lexers) Regular

More information

Context-Free Grammars

Context-Free Grammars Context-Free Grammars Describing Languages We've seen two models for the regular languages: Automata accept precisely the strings in the language. Regular expressions describe precisely the strings in

More information

Regular Expressions & Automata

Regular Expressions & Automata Regular Expressions & Automata CMSC 132 Department of Computer Science University of Maryland, College Park Regular expressions Notation Patterns Java support Automata Languages Finite State Machines Turing

More information

Programming Assignments

Programming Assignments ELEC 486/586, Summer 2017 1 Programming Assignments 1 General Information 1.1 Software Requirements Detailed specifications are typically provided for the software to be developed for each assignment problem.

More information

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018 Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018 Lecture 11 Ana Bove April 26th 2018 Recap: Regular Languages Decision properties of RL: Is it empty? Does it contain this word? Contains

More information

CT32 COMPUTER NETWORKS DEC 2015

CT32 COMPUTER NETWORKS DEC 2015 Q.2 a. Using the principle of mathematical induction, prove that (10 (2n-1) +1) is divisible by 11 for all n N (8) Let P(n): (10 (2n-1) +1) is divisible by 11 For n = 1, the given expression becomes (10

More information

Finite Automata. Dr. Nadeem Akhtar. Assistant Professor Department of Computer Science & IT The Islamia University of Bahawalpur

Finite Automata. Dr. Nadeem Akhtar. Assistant Professor Department of Computer Science & IT The Islamia University of Bahawalpur Finite Automata Dr. Nadeem Akhtar Assistant Professor Department of Computer Science & IT The Islamia University of Bahawalpur PhD Laboratory IRISA-UBS University of South Brittany European University

More information

Outline. 1 Scanning Tokens. 2 Regular Expresssions. 3 Finite State Automata

Outline. 1 Scanning Tokens. 2 Regular Expresssions. 3 Finite State Automata Outline 1 2 Regular Expresssions Lexical Analysis 3 Finite State Automata 4 Non-deterministic (NFA) Versus Deterministic Finite State Automata (DFA) 5 Regular Expresssions to NFA 6 NFA to DFA 7 8 JavaCC:

More information

Midterm I (Solutions) CS164, Spring 2002

Midterm I (Solutions) CS164, Spring 2002 Midterm I (Solutions) CS164, Spring 2002 February 28, 2002 Please read all instructions (including these) carefully. There are 9 pages in this exam and 5 questions, each with multiple parts. Some questions

More information

Implementation of Lexical Analysis

Implementation of Lexical Analysis Implementation of Lexical Analysis Outline Specifying lexical structure using regular expressions Finite automata Deterministic Finite Automata (DFAs) Non-deterministic Finite Automata (NFAs) Implementation

More information

COP Programming Assignment #7

COP Programming Assignment #7 1 of 5 03/13/07 12:36 COP 3330 - Programming Assignment #7 Due: Mon, Nov 21 (revised) Objective: Upon completion of this program, you should gain experience with operator overloading, as well as further

More information

Homework Assignment #3

Homework Assignment #3 CS 540-2: Introduction to Artificial Intelligence Homework Assignment #3 Assigned: Monday, February 20 Due: Saturday, March 4 Hand-In Instructions This assignment includes written problems and programming

More information

Lexical Analysis 1 / 52

Lexical Analysis 1 / 52 Lexical Analysis 1 / 52 Outline 1 Scanning Tokens 2 Regular Expresssions 3 Finite State Automata 4 Non-deterministic (NFA) Versus Deterministic Finite State Automata (DFA) 5 Regular Expresssions to NFA

More information

CS Homework 10 p. 1. CS Homework 10

CS Homework 10 p. 1. CS Homework 10 CS 111 - Homework 10 p. 1 Deadline 11:59 pm on Friday, December 2, 2016 How to submit Each time you would like to submit your work: CS 111 - Homework 10 If your files are not already on nrs-labs, be sure

More information

Tips from the experts: How to waste a lot of time on this assignment

Tips from the experts: How to waste a lot of time on this assignment Com S 227 Spring 2018 Assignment 1 100 points Due Date: Friday, September 14, 11:59 pm (midnight) Late deadline (25% penalty): Monday, September 17, 11:59 pm General information This assignment is to be

More information

Regular Languages and Regular Expressions

Regular Languages and Regular Expressions Regular Languages and Regular Expressions According to our definition, a language is regular if there exists a finite state automaton that accepts it. Therefore every regular language can be described

More information

Formal Languages and Compilers Lecture VI: Lexical Analysis

Formal Languages and Compilers Lecture VI: Lexical Analysis Formal Languages and Compilers Lecture VI: Lexical Analysis Free University of Bozen-Bolzano Faculty of Computer Science POS Building, Room: 2.03 artale@inf.unibz.it http://www.inf.unibz.it/ artale/ Formal

More information

Programming Assignment IV Due Thursday, November 18th, 2010 at 11:59 PM

Programming Assignment IV Due Thursday, November 18th, 2010 at 11:59 PM Programming Assignment IV Due Thursday, November 18th, 2010 at 11:59 PM 1 Introduction In this assignment, you will implement a code generator for Cool. When successfully completed, you will have a fully

More information