CS241 Week 6 Tutorial Solutions

Similar documents
The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER MACHINES AND THEIR LANGUAGES ANSWERS

CS 573 Automata Theory and Formal Languages

Harvard University Computer Science 121 Midterm October 23, 2012

Closure Properties of Regular Languages

1 PYTHAGORAS THEOREM 1. Given a right angled triangle, the square of the hypotenuse is equal to the sum of the squares of the other two sides.

CS311 Computational Structures Regular Languages and Regular Grammars. Lecture 6

Intermediate Math Circles Wednesday, November 14, 2018 Finite Automata II. Nickolas Rollick a b b. a b 4

Nondeterministic Finite Automata

NON-DETERMINISTIC FSA

Running an NFA & the subset algorithm (NFA->DFA) CS 350 Fall 2018 gilray.org/classes/fall2018/cs350/

Homework 3 Solutions

Chapter 4 Regular Grammar and Regular Sets. (Solutions / Hints)

Prefix-Free Regular-Expression Matching

CSC 311 Theory of Computation

Parse trees, ambiguity, and Chomsky normal form

Formal languages, automata, and theory of computation

Lecture 6 Regular Grammars

Regular languages refresher

Semantic Analysis. CSCI 3136 Principles of Programming Languages. Faculty of Computer Science Dalhousie University. Winter Reading: Chapter 4

CS375: Logic and Theory of Computing

Finite State Automata and Determinisation

Chapter Five: Nondeterministic Finite Automata. Formal Language, chapter 5, slide 1

FABER Formal Languages, Automata and Models of Computation

CS 310 (sec 20) - Winter Final Exam (solutions) SOLUTIONS

CS 330 Formal Methods and Models Dana Richards, George Mason University, Spring 2016 Quiz Solutions

Counting Paths Between Vertices. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs

Some Theory of Computation Exercises Week 1

Assignment 1 Automata, Languages, and Computability. 1 Finite State Automata and Regular Languages

Minimal DFA. minimal DFA for L starting from any other

First Midterm Examination

CS 301. Lecture 04 Regular Expressions. Stephen Checkoway. January 29, 2018

First Midterm Examination

Finite Automata-cont d

SEMANTIC ANALYSIS PRINCIPLES OF PROGRAMMING LANGUAGES. Norbert Zeh Winter Dalhousie University 1/28

CS 275 Automata and Formal Language Theory

Non-deterministic Finite Automata

Technische Universität München Winter term 2009/10 I7 Prof. J. Esparza / J. Křetínský / M. Luttenberger 11. Februar Solution

Project 6: Minigoals Towards Simplifying and Rewriting Expressions

CS 373, Spring Solutions to Mock midterm 1 (Based on first midterm in CS 273, Fall 2008.)

Grammar. Languages. Content 5/10/16. Automata and Languages. Regular Languages. Regular Languages

1 Nondeterministic Finite Automata

Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem 2/16/15

NFAs continued, Closure Properties of Regular Languages

I. Theory of Automata II. Theory of Formal Languages III. Theory of Turing Machines

Regular expressions, Finite Automata, transition graphs are all the same!!

SWEN 224 Formal Foundations of Programming WITH ANSWERS

Talen en Automaten Test 1, Mon 7 th Dec, h45 17h30

Overview HC9. Parsing: Top-Down & LL(1) Context-Free Grammars (1) Introduction. CFGs (3) Context-Free Grammars (2) Vertalerbouw HC 9: Ch.

For convenience, we rewrite m2 s m2 = m m m ; where m is repeted m times. Since xyz = m m m nd jxyj»m, we hve tht the string y is substring of the fir

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

Let's start with an example:

CSE : Exam 3-ANSWERS, Spring 2011 Time: 50 minutes

Parsing and Pattern Recognition

Convert the NFA into DFA

Anatomy of a Deterministic Finite Automaton. Deterministic Finite Automata. A machine so simple that you can understand it in less than one minute

Tutorial Worksheet. 1. Find all solutions to the linear system by following the given steps. x + 2y + 3z = 2 2x + 3y + z = 4.

Thoery of Automata CS402

Java II Finite Automata I

Regular Language. Nonregular Languages The Pumping Lemma. The pumping lemma. Regular Language. The pumping lemma. Infinitely long words 3/17/15

CS 330 Formal Methods and Models

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER LANGUAGES AND COMPUTATION ANSWERS

a b b a pop push read unread

Compiler Design. Spring Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz

Non-deterministic Finite Automata

Exercises Chapter 1. Exercise 1.1. Let Σ be an alphabet. Prove wv = w + v for all strings w and v.

CS375: Logic and Theory of Computing

Lecture 08: Feb. 08, 2019

Table of contents: Lecture N Summary... 3 What does automata mean?... 3 Introduction to languages... 3 Alphabets... 3 Strings...

5. (±±) Λ = fw j w is string of even lengthg [ 00 = f11,00g 7. (11 [ 00)± Λ = fw j w egins with either 11 or 00g 8. (0 [ ffl)1 Λ = 01 Λ [ 1 Λ 9.

Computing data with spreadsheets. Enter the following into the corresponding cells: A1: n B1: triangle C1: sqrt

Lecture 09: Myhill-Nerode Theorem

NFAs continued, Closure Properties of Regular Languages

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

CHAPTER 1 Regular Languages. Contents

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

Tutorial Automata and formal Languages

Algorithm Design and Analysis

Normal Forms for Context-free Grammars

Automata and Languages

Algorithm Design and Analysis

2.4 Linear Inequalities and Interval Notation

CMSC 330: Organization of Programming Languages

CS 330 Formal Methods and Models

Algorithms & Data Structures Homework 8 HS 18 Exercise Class (Room & TA): Submitted by: Peer Feedback by: Points:

Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Kleene-*

Discrete Structures, Test 2 Monday, March 28, 2016 SOLUTIONS, VERSION α

Data Structures and Algorithm. Xiaoqing Zheng

1.4 Nonregular Languages

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. NFA for (a b)*abb.

6.5 Improper integrals

More on automata. Michael George. March 24 April 7, 2014

CS 275 Automata and Formal Language Theory

I1 = I2 I1 = I2 + I3 I1 + I2 = I3 + I4 I 3

Non Right Angled Triangles

Bases for Vector Spaces

System Validation (IN4387) November 2, 2012, 14:00-17:00

CS 314 Principles of Programming Languages

Formal Languages and Automata

12.4 Similarity in Right Triangles

NFA DFA Example 3 CMSC 330: Organization of Programming Languages. Equivalence of DFAs and NFAs. Equivalence of DFAs and NFAs (cont.

Transcription:

241 Week 6 Tutoril olutions Lnguges: nning & ontext-free Grmmrs Winter 2018 1 nning Exerises 1. 0x0x0xd HEXINT 0x0 I x0xd 2. 0xend--- HEXINT 0xe I nd ER -- MINU - 3. 1234-120x INT 1234 INT -120 I x 4. end--en-3 I end ER -- ERROR en- 5. 01end-end10 ZERO 0 INT 1 EN end MINU - I end10 1

2 ontext-free Grmmr Exerises 2.1 erivtions Let G e the following grmmr: 1. how tht the word is in L(G) y giving derivtion. 2. Whih of the following re vlid derivtions of words in L(G)? () () () (d) (e) () is invlid sine there is no rule in G. () is invlid sine there is no rule in G. () is vlid. (d) is invlid sine is not the strt symol of the grmmr. (e) is invlid sine there is no rule. However, it would e vlid if we sid =, sine. 2

2.2 esigning Grmmrs 1. Write ontext-free grmmrs for the following lnguges: () The lnguge L = {my, nme, is, inigo, montoy}. () The lnguge of ll words over Σ = {,, } not eginning with. () The lnguge defined y the regulr expression (0 1) ((00) 1) 010. (d) The lnguge L = { n n m d m : n, m N}, where n mens n opies of in row. (e) The lnguge of plindromes over Σ = {, }. plindrome is word or phrse whih is spelled the sme forwrds nd kwrds, for exmple, rer, or le ws I ere I sw El. () This is just union, whih is very esy to enfore in grmmr. my nme is inigo montoy () We need to e reful here: does not egin with! Otherwise, we simply llow to hve n or followed y, where represents nything. () It turns out every regulr expression n e onverted vi simple lgorithm to regulr expression. We n do tht to get grmmr tht looks firly similr to this one, ut it my help to try to enode,,, nd s FGs nd then think out how you might omine them. 010 0 1 1 00 3

(d) This is simply two opies of the mthing prentheses grmmr, where nd d re our prentheses in the two prts of the prolem. We n simply write down those two grmmrs then omine them with. d (e) Even-length plindromes ren t too d: we just need to enfore tht we dd n or to oth the strt nd end t the sme time. However, we need to e reful: is plindrome, nd some (odd-length) plindromes hve single opy of or in the ext entre. omining these ides we get: 2. rgue tht every regulr lnguge is ontext-free y desriing how to onvert ny regulr expression into ontext-free grmmr. Rell tht regulr expression tkes one of five forms. We will present grmmr whih hndles eh se: then y indution on the omplexity of the regulr expression we see tht ny regulr expression n e enoded in FG, nd thus every regulr lnguge is ontext-free. R =, the empty word. The orresponding prodution is simply. R =, single symol. The orresponding prodution is simply. R = R 1 R 2, the ontention of two regulr expressions. The orresponding prodution is 1 2, where 1, 2 re the rules orresponding to R 1, R 2. R = R 1 R 2, the union of two regulr expressions. 1 nd 2. R = R1, the Kleene losure of regulr expression. 1 nd. This hs two orresponding produtions: One gin, we need two produtions: ine ll regulr expressions tke one of these four forms nd every regulr lnguge n e enoded y regulr expression, every regulr lnguge is ontext-free. 4

3 Prse Tree Exerises Let G e the following grmmr: 1. Find prse trees for the following words: () () () For ll of these, we simply need to find derivtion, fter whih the prse tree omes firly nturlly. Note tht in the pth we enfore tht there re the sme numer of s nd s, ut ny numer of s, wheres in the pth we enfore tht there re the sme numer of s nd s, ut ny numer of s. s result, we simply need to pik the pproprite strting point given the numer of s, s, nd s in the word, nd fter tht there is only one hoie t every step. () () 5

() 2. Prove tht G is miguous y finding two prse trees for the word. The key oservtion here is tht L(G) = { i j k : i = j or j = k}, nd hs i = j = k, so we n hoose to enfore either the i = j or the j = k onditions in the grmmr. Enforing i = j we get: Enforing j = k we get: 6