PROGRAMMING LANGUAGES

Slides:



Advertisements
Similar presentations
Pumping Lemma Examples
Advertisements

L ECTURE 3 T HEORY OF AUTOMATA. E QUIVALENT R EGULAR E XPRESSIONS Definition Two regular expressions are said to be equivalent if they generate the same.
Regular Grammars Formal definition of a regular expression.
Regular expressions Sipser 1.3 (pages 63-76). CS 311 Mount Holyoke College 2 Looks familiar…
CS 3240 – Chapter 3.  How would you delete all C++ files from a directory from the command line?  How about all PowerPoint files that start with the.
Strings and Languages Operations
1 CSC 3130: Automata theory and formal languages Tutorial 4 KN Hung Office: SHB 1026 Department of Computer Science & Engineering.
1 Module 33 Pushdown Automata (PDA’s) –Another example.
Regular expressions Sipser 1.3 (pages 63-76). CS 311 Fall Looks familiar…
1 Regular Expressions/Languages Regular languages –Inductive definitions –Regular expressions syntax semantics Not covered in lecture.
Case-Level Research Designs
Regular Languages A language is regular over  if it can be built from ;, {  }, and { a } for every a 2 , using operators union ( [ ), concatenation.
Theory Of Automata By Dr. MM Alam
CMSC 330 Exercise: Write a Ruby function that takes an array of names in “Last, First Middle” format and returns the same list in “First Middle Last” format.
Second lecture REGULAR EXPRESSION. Regular Expression.
Lexical Analysis CSE 340 – Principles of Programming Languages Fall 2015 Adam Doupé Arizona State University
Theory Of Automata By Dr. MM Alam
Lecture # 1 (Automata Theory)
1 Welcome to ! Theory Of Automata. 2 Text and Reference Material 1.Introduction to Computer Theory, by Daniel I. Cohen, John Wiley and Sons, Inc., 1991,
Module 2 How to design Computer Language Huma Ayub Software Construction Lecture 7 1.
CMSC 330: Organization of Programming Languages Theory of Regular Expressions.
1 Language Definitions Lecture # 2. Defining Languages The languages can be defined in different ways, such as Descriptive definition, Recursive definition,
1 Chapter 1 Introduction to the Theory of Computation.
Lecture # 3 Regular Expressions 1. Introduction In computing, a regular expression provides a concise and flexible means to "match" (specify and recognize)
2. Scanning College of Information and Communications Prof. Heejin Park.
Module 2 How to design Computer Language Huma Ayub Software Construction Lecture 8.
L ECTURE 3 Chapter 4 Regular Expressions. I MPORTANT T ERMS Regular Expressions Regular Languages Finite Representations.
Regular Grammars Chapter 7. Regular Grammars A regular grammar G is a quadruple (V, , R, S), where: ● V is the rule alphabet, which contains nonterminals.
Regular Grammars Chapter 7 1. Regular Grammars A regular grammar G is a quadruple (V, , R, S), where: ● V is the rule alphabet, which contains nonterminals.
1 Simplification of Context-Free Grammars Some useful substitution rules. Removing useless productions. Removing -productions. Removing unit-productions.
CSC312 Automata Theory Lecture # 3 Languages-II. Formal Language A formal language is a set of words—that is, strings of symbols drawn from a common alphabet.
Recursive Definations Regular Expressions Ch # 4 by Cohen
Brian K. Strickland a ba Λ a aa b Λ -NFA for Regular Expression (aab)*(a + aba)*
CST229 Week 7 Questions or concerns? Hand back Test#1 & Homework #4 – Test1 Average (45/50) Reading: Chapters 12&13 Chapter 12 – Grammar – production rules.
CSCI 3130: Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong Limitations.
Lecture # Book Introduction to Theory of Computation by Anil Maheshwari Michiel Smid, 2014 “Introduction to computer theory” by Daniel I.A. Cohen.
Lecture # 4.
Mathematical Foundations of Computer Science Chapter 3: Regular Languages and Regular Grammars.
Transparency No. 2-1 Formal Language and Automata Theory Homework 2.
Lecture 2 Theory of AUTOMATA
1 Section 11.1 Regular Languages Problem: Suppose the input strings to a program must be strings over the alphabet {a, b} that contain exactly one substring.
CSC312 Automata Theory Lecture # 8 Chapter # 5 (Cont…) Finite Automata.
1 Chapter 3 Regular Languages.  2 3.1: Regular Expressions (1)   Regular Expression (RE):   E is a regular expression over  if E is one of:
1 Strings and Languages Lecture 2-3 Ref. Handout p12-17.
Lecture 03: Theory of Automata:2014 Asif Nawaz Theory of Automata.
1 1. Eliminate all  -transitions from the following FA without changing the number of states and the language accepted by the automaton. You should also.
CHAPTER TWO LANGUAGES By Dr Zalmiyah Zakaria.
Recap lecture 5 Different notations of transition diagrams, languages of strings of even length, Odd length, starting with b, ending in a (with different.
Pumping Lemma.
Theory of Computation Lecture #
Lecture # 2.
PROGRAMMING LANGUAGES
CS510 Compiler Lecture 2.
Regular Languages, Regular Operations, Closure
CSC-2259 Discrete Structures
Lexical Analysis CSE 340 – Principles of Programming Languages
Theory of Automata.
Regular Expressions (Examples)
LANGUAGES Prepared by: Paridah Samsuri Dept. of Software Engineering
CSC312 Automata Theory Lecture # 4 Languages-III.
Chapter 7 Regular Grammars
Recap lecture 29 Example of prefixes of a language, Theorem: pref(Q in R) is regular, proof, example, Decidablity, deciding whether two languages are equivalent.
CS 350 — Fall 2018 gilray.org/classes/fall2018/cs350/
Pumping Lemma.
Chapter 1 Introduction to the Theory of Computation
CSC312 Automata Theory Lecture # 5 Chapter # 4 Cont…
CSC312 Automata Theory Lecture # 3 Languages-II.
Recap Lecture 3 RE, Recursive definition of RE, defining languages by RE, { x}*, { x}+, {a+b}*, Language of strings having exactly one aa, Language of.
LECTURE # 07.
Finite Automata Part Three
Presentation transcript:

PROGRAMMING LANGUAGES CS 222 HW1 SOL PROGRAMMING LANGUAGES

There are 3 cases : (a ) + ( b )+( c ) The regular expression of the string over Σ={a,b,c} in which all the a’sprecede the b’swhich in turn precede the c’s, but without the empty string. Sol : String in R : a,b,c,ab,ac,bc,aa,bb,cc,aab,aac,bbc,aac,abbcc,bccc String not in R : ,ba,ca,cb,cab,acb,bbba,… There are 3 cases : (a ) + ( b )+( c ) R = ( aa*b*c*) + (a*b*bc*) + (a*b*cc*) R = (a+b*c*) + (a*b+c*) + (a*b*c+) a+ b+ c+

The string are combination of 1 and 01 such as 1 01 = 101 The regular expression of the string over ={0,1} in which the string end with 1 and does not contain the substring 00. Sol : String in R : 1,01,11,011,101,111,1011,010101,11011101,… String not in R : ,00,10,001,1001,1100,… The string are combination of 1 and 01 such as 1 01 = 101 1 1 1 = 111 , 01 01 01 = 010101 R = (1+01)+

We need odd-length strings , which is even-length + 1. So that , The regular expression of the string over ={a,b} consists of all odd-length strings Sol : String in R : a,b,aaa,bbb,aab,aba,abb,bba,abbba,… String not in R : ,ab,ba,aa,bb,abab,abba,aaaa,bbbb,… The even-length strings are the combination of aa,ab,ba,bb such as aa ba = aaba , ab ab = abab, bb aa = bbaa . (aa + ab + ba + bb)* We need odd-length strings , which is even-length + 1. So that , R = (aa + ab + ba + bb)*(a + b)

The pattern of string is a b b cc The regular expression of the string over ={a,b,c} that begin with a, contain exactly two b's, and end with cc. Sol : String in R : abbcc,aaaabcaacbaaacacc,acccaacbacacbcacacc,… String not in R : ,ab,abc,abbc,babb,bacc,abcc,… The pattern of string is a b b cc R = a(a + c)*b(a + c)*b(a + c)*cc (a+c)* (a+c)* (a+c)*

Every “a” must be followed by b or c. R = (b + c + a(b + c))*(λ + a) The regular expression of the string over ={a,b,c} that do not contain substring aa. Sol : String in R : ,a,b,c,ab,ac,ba,bc,ca,cb,aba,bbb,ccc,babbbac,… String not in R :,aab,baabc,bcaa,… Every “a” must be followed by b or c. R = (b + c + a(b + c))*(λ + a)

There are two cases : 1. even number of a’s or 2. odd number of b’s The regular expression of the string over ={a,b} with an even number of a's or an odd number of b's. Sol : String in R : ,aa,b,ab,ba,bc,aba,bbb,abab,baba,babab,… String not in R : a,bab,bba,… There are two cases : 1. even number of a’s or 2. odd number of b’s Even number of a’s : b* a b* a b* => (b*ab*ab*)* Odd number of b’s : (a*ba*ba*)* a*ba* => (a*ba*ba*)*a*ba* R = ((b*ab*ab*)* + (a*ba*ba*)*a*ba*) Even # b

The string pattern is : (ba+ca+ab+ac) The regular expression of the string over ={a,b,c} with an even length and contain exactly one a. Sol : String in R : ba,ab,ac,ca,cbac,bcab,bcba,abbbcccb, … String not in R : ,a,b,c,bab,bba,… The string pattern is : (ba+ca+ab+ac) E(b+c) = (bb+bc+cb+cc)* = ((b+c)(b+c))* R = ((b+c)(b+c))*(b+c)a((b+c)(b+c))* (b+c)a+a(b+c) E(b+c) E(b+c)

There are four cases : 1. ab b 2. ba b 3. b ab 4. b ba The regular expression of the string over ={a,b} with an odd length and contain exactly two b’s. Sol : String in R : abb,bab,bba,aababaa,aabaaba,abaabaa,abaaba,ababa… String not in R : ,a,abab,bbaa,ab,bbb,… There are four cases : 1. ab b 2. ba b 3. b ab 4. b ba E(a) = (aa)* , O(a) = (aa)*a R = (aa)*((ab+ba)(aa)*b+(bb+(ab+ba)(aa)*ab)a)(aa)* E(a) E(a) E(a) E(a) E(a) E(a) E(a) E(a) E(a) E(a) E(a) E(a)