CMSC330 Summer 2009 Midterm 1: Ruby and Re~lu[ar Lan~ua~les

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

Theory of Computation Dr. Weiss Extra Practice Exam Solutions

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

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

Midterm I (Solutions) CS164, Spring 2002

Midterm I - Solution CS164, Spring 2014

6 NFA and Regular Expressions

CMSC330 Spring 2015 Midterm #1 9:30am/11:00am/12:30pm

CMSC330 Fall 2016 Midterm #2 2:00pm/3:30pm

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

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

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

CMSC 330, Fall 2018 Midterm 2

CMSC330 Spring 2015 Midterm #1 9:30am/11:00am/12:30pm

CMSC330 Fall 2014 Midterm 1 Solution

CMSC330 Fall 2014 Midterm 1 Grading

Chapter Seven: Regular Expressions

Theory of Computations Spring 2016 Practice Final Exam Solutions

CSE450. Translation of Programming Languages. Lecture 20: Automata and Regular Expressions

Theory of Computations Spring 2016 Practice Final

Formal Languages and Compilers Lecture VI: Lexical Analysis

Midterm Exam II CIS 341: Foundations of Computer Science II Spring 2006, day section Prof. Marvin K. Nakayama

CS143 Midterm Fall 2008

CMSC330 Spring 2018 Midterm 2 9:30am/ 11:00am/ 3:30pm

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

CMSC 330, Fall 2018 Midterm 2

Automating Construction of Lexers

Implementation of Lexical Analysis

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

Implementation of Lexical Analysis

Regular Languages and Regular Expressions

CSE450. Translation of Programming Languages. Automata, Simple Language Design Principles

CSE 401 Midterm Exam 11/5/10

CSE 105 THEORY OF COMPUTATION

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

CS52 - Assignment 10

CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

Lecture 2 Finite Automata

Midterm Solutions COMS W4115 Programming Languages and Translators Wednesday, March 25, :10-5:25pm, 309 Havemeyer

UVa ID: NAME (print): CS 4501 LDI Midterm 1

Converting a DFA to a Regular Expression JP

Lexical Analysis. Chapter 2

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

HKN CS 374 Midterm 1 Review. Tim Klem Noah Mathes Mahir Morshed

Theory Bridge Exam Example Questions Version of June 6, 2008

CS103 Handout 14 Winter February 8, 2013 Problem Set 5

ECE 468/573 Midterm 1 September 30, 2015

Lexical Analysis. Implementation: Finite Automata

JNTUWORLD. Code No: R

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

Translator Design CRN Test 3 Revision 1 CMSC 4173 Spring 2012

CS164: Midterm I. Fall 2003

ECE251 Midterm practice questions, Fall 2010

CMSC330 Fall 2017 Final Exam

Implementation of Lexical Analysis

Lexical Analysis. Lecture 2-4

Answer All Questions. All Questions Carry Equal Marks. Time: 20 Min. Marks: 10.

CSE 373 Winter 2009: Midterm #1 (closed book, closed notes, NO calculators allowed)

SYED AMMAL ENGINEERING COLLEGE (An ISO 9001:2008 Certified Institution) Dr. E.M. Abdullah Campus, Ramanathapuram

CSE 105 THEORY OF COMPUTATION

CS 432 Fall Mike Lam, Professor. Finite Automata Conversions and Lexing

Lexical Analysis. Lecture 3-4

Lexical Analysis - 2

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

Exercise 2: Automata Theory

Midterm Exam. CSCI 3136: Principles of Programming Languages. February 20, Group 2

Computer Science /21/2000

Compiler Design. 2. Regular Expressions & Finite State Automata (FSA) Kanat Bolazar January 21, 2010

CMSC330 Spring 2016 Midterm #2 9:30am/12:30pm/3:30pm

CMSC330 Fall 2009 Final Exam

CS 181 EXAM #1 NAME. You have 90 minutes to complete this exam. You may state without proof any fact taught in class or assigned as homework.

CSCI 2132 Software Development. Lecture 7: Wildcards and Regular Expressions

CS143 Handout 20 Summer 2011 July 15 th, 2011 CS143 Practice Midterm and Solution

Final Course Review. Reading: Chapters 1-9

Structure of Programming Languages Lecture 3

Compiler Construction

Ambiguous Grammars and Compactification

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

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

Introduction to Lexical Analysis

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

Formal Languages and Compilers Lecture IV: Regular Languages and Finite. Finite Automata

CS2 Practical 2 CS2Ah

CS 181 B&C EXAM #1 NAME. You have 90 minutes to complete this exam. You may assume without proof any statement proved in class.

Optimizing Finite Automata

Chapter Eight: Regular Expression Applications. Formal Language, chapter 8, slide 1

Computer Science 217 Final Exam January 25, :30-4:30pm

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)

Lexical Analysis. Lecture 3. January 10, 2018

Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan

CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

CMSC330 Fall 2016 Midterm #1 2:00pm/3:30pm

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

Computation, Computers, and Programs. Administrivia. Resources. Course texts: Kozen: Introduction to Computability Hickey: Introduction to OCaml

Where We Are. CMSC 330: Organization of Programming Languages. This Lecture. Programming Languages. Motivation for Grammars

ECE 468/573 Midterm 1 October 1, 2014

CSE 582 Autumn 2002 Exam 11/26/02

COMPILER DESIGN UNIT I LEXICAL ANALYSIS. Translator: It is a program that translates one language to another Language.

CSE au Final Exam Sample Solution

Transcription:

Name: CMSC330 Summer 2009 Midterm 1: Ruby and Re~lu[ar Lan~ua~les Instructions: Show your work for a[[ problems. If you need extra space, ask for a sheet of paper and [abe[ your work (i.e. which problem your work corresponds to). For two points extra credit, list one thin~ that you like about this course and one thin~ that you do not like about this course on this pa~e.

1. Typing a. Explain the difference between dynamic types and static types without using the words "dynamic" or "static". (2pts) b. Give an example of a language that uses static types and one that uses dynamic types (and [abe[ which language uses which). (2pts) 2. Regular Expressions and languages a. Give a regular expression for the following Ruby regular expressions. You may use the symbol Z to stand for "any character": (8 pts) i. /phone[abc]/ ii. iii. /^phone/ /^phone.*/ iv. l^phone$1.p hor~

b. Give a DFA/NFA for the fo[[owin~ regular expressions. Do not include dead states. State whether you are drawin~ an NFA or a DFA (circle one). (Spts) i. ablc (~(~ ii. (01 I1)*(1010)* DFA NFA 0

c. What is the language.0f the following regular expressions? Give an English description. (4 pts) A = ["abc", "bc"] (01011010)* d. Give a regular expression for the following languages: (6 pts) i. All binary numbers that contain at least two 0s All binary numbers that do not contain the substring 00 3. Ruby programming (24 pts) Write a Ruby program called phone.rb to process phone numbers contained in a text file. We are interested in recording the number of times each area code appears in the file. Your code should open a file where the file name is provided in the first argument on the command line, as: %ruby -w phone.rb input_file.txt You need to read in the file and find all occurrences of valid phone numbers in the following example format: (555)-555-5555 There should be no whitespace or other characters between any digits, parentheses, or dashes as shown above. You should count the number of times each different area code appears in the input file. After you have read the file,

you shoutd print out the area codes and the number of times each area code appeared in sorted order by area code, each area code on a new line fottowed by a comma, and then the count. Below are example inputs and outputs: Input (301)-555~5555 (301) This is random text here 555-5555. (434)-555-5555 and some more text(434)-555-5555. (703)-555-5555 (301)-555-5555 (703)-555-5555 (202)-555-5555 (301)-555-5555 434,2 202, I 301,2 703,2 Write code for phone.rb below:

4. Finite Automata a. What is the order of the runtime for a DFA to accept a string s? You may assume that s has n characters and provide the big-o notation, or you may explain in English what the runtime is based on the length of the input. (2pts) b. Imagine we have an NFA and 100,000 strings for which we want to see if the NFA accepts. Name one reason why we would want to convert the NFA into a DFA in this scenario. (2pts) c. Assume we have a DFA and an NFA for the same regular expression, neither of which have any dead states. In terms of the number of states D in the DFA and N in the NFA, which of the following is true (circle one or more)? (2pts) N F@

d. Draw a NFA for binary numbers that start and end in the same digit. Do not include dead states. (4pts) e. Give a regular expression for the language represented by the~be[ow. (4pts).. 1 1

Answer to 4.e: f. What does "non-deterministic" and "deterministic" mean in the context of an NFA/DFA(non-deterministic finite automata/deterministic finite automata)? (2pts)

5. Reductions and conversions a. Reduce the resu[ar expression ab I c* to a NFA. You may use the algorithm ~iven in class. Do not include dead states. (Spts)

b. Reduce the fo[[owin~ NFA to a DFA usin8 the construction ~iven in class. Do not include dead states. (10 pts) ( ~ )

c. Minimize the DFA betow. You may use the atsorithm provided in crass. Do not inctude dead states. (8pts) b a

d. Give the complement of the DFA below (draw the complement DFA). (4pts) b

Extra credit (for one point each): 1. What language does the following automation recognize? Hint: it accepts 2000 and 2008 but not 2009.

2. Draw an NFA that accepts art binary strings with an even number of zeros, with any number of ls in between. Exampte strin~is in the [an~ua~le: 010, 00, 0t01, 10101, 01111000, etc.