Chapter 2 Languages.

Slides:



Advertisements
Similar presentations
Specifying Languages Our aim is to be able to specify languages for use in the computer. The sketch of the FSA is easy for us to understand, but difficult.
Advertisements

Formal Languages Languages: English, Spanish,... PASCAL, C,... Problem: How do we define a language? i.e. what sentences belong to a language? e.g.Large.
Chapter 6 Languages: finite state machines
COMP-421 Compiler Design Presented by Dr Ioanna Dionysiou.
YES-NO machines Finite State Automata as language recognizers.
Chapter Chapter Summary Languages and Grammars Finite-State Machines with Output Finite-State Machines with No Output Language Recognition Turing.
Regular Grammars Formal definition of a regular expression.
CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x.
Regular Languages Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 3 Comments, additions and modifications.
Languages, grammars, and regular expressions
Regular Languages Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 3 Comments, additions and modifications.
Fall 2005 CSE 467/567 1 Formal languages regular expressions regular languages finite state machines.
79 Regular Expression Regular expressions over an alphabet  are defined recursively as follows. (1) Ø, which denotes the empty set, is a regular expression.
Normal forms for Context-Free Grammars
Context-Free Grammars Chapter 3. 2 Context-Free Grammars and Languages n Defn A context-free grammar is a quadruple (V, , P, S), where  V is.
Chapter 9 Turing Machine (TMs).
Lecture 1 String and Language. String string is a finite sequence of symbols. For example, string ( s, t, r, i, n, g) CS4384 ( C, S, 4, 3, 8) (1,
Regular Languages A language is regular over  if it can be built from ;, {  }, and { a } for every a 2 , using operators union ( [ ), concatenation.
Languages & Strings String Operations Language Definitions.
Finite-State Machines with No Output
::ICS 804:: Theory of Computation - Ibrahim Otieno SCI/ICT Building Rm. G15.
CSC312 Automata Theory Lecture # 2 Languages.
CSC312 Automata Theory Lecture # 2 Languages.
Formal Methods in SE Theory of Automata Qasiar Javaid Assistant Professor Lecture # 06.
Lecture Two: Formal Languages Formal Languages, Lecture 2, slide 1 Amjad Ali.
Winter 2007SEG2101 Chapter 71 Chapter 7 Introduction to Languages and Compiler.
CMSC 330: Organization of Programming Languages Theory of Regular Expressions.
Two examples English-Words English-Sentences alphabet S ={a,b,c,d,…}
Introduction to CS Theory Lecture 3 – Regular Languages Piotr Faliszewski
1 Regular Expressions. 2 Regular expressions describe regular languages Example: describes the language.
1 INFO 2950 Prof. Carla Gomes Module Modeling Computation: Language Recognition Rosen, Chapter 12.4.
1 Chapter 1 Introduction to the Theory of Computation.
Languages, Grammars, and Regular Expressions Chuck Cusack Based partly on Chapter 11 of “Discrete Mathematics and its Applications,” 5 th edition, by Kenneth.
Grammars CPSC 5135.
Lecture # 5 Pumping Lemma & Grammar
Chapter 5: Sequences, Mathematical Induction, and Recursion 5.9 General Recursive Definitions and Structural Induction 1 Erickson.
Regular Expressions Hopcroft, Motawi, Ullman, Chap 3.
Regular Expressions and Languages A regular expression is a notation to represent languages, i.e. a set of strings, where the set is either finite or contains.
Kleene’s Theorem Group No. 3 Presented To Mam Amina Presented By Roll No Roll No Roll No Roll No Group No. 3 Presented To Mam.
Language: Set of Strings
Strings and Languages CS 130: Theory of Computation HMU textbook, Chapter 1 (Sec 1.5)
Chapter 4 Pumping Lemma Properties of Regular Languages Decidable questions on Regular Languages.
1 A well-parenthesized string is a string with the same number of (‘s as )’s which has the property that every prefix of the string has at least as many.
Specifying Languages Our aim is to be able to specify languages for use in the computer. The sketch of an FSA is easy for us to understand, but difficult.
Chapter 6 Properties of Regular Languages. 2 Regular Sets and Languages  Claim(1). The family of languages accepted by FSAs consists of precisely the.
CS 203: Introduction to Formal Languages and Automata
Recursive Definations Regular Expressions Ch # 4 by Cohen
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
Grammars A grammar is a 4-tuple G = (V, T, P, S) where 1)V is a set of nonterminal symbols (also called variables or syntactic categories) 2)T is a finite.
Classifications LanguageGrammarAutomaton Regular, right- linear Right-linear, left-linear DFA, NFA Context-free PDA Context- sensitive LBA Recursively.
November 2003Computational Morphology III1 CSA405: Advanced Topics in NLP Xerox Notation.
Formal Languages and Grammars
Strings and Languages Denning, Section 2.7. Alphabet An alphabet V is a finite nonempty set of symbols. Each symbol is a non- divisible or atomic object.
Transparency No. 2-1 Formal Language and Automata Theory Homework 2.
Binary Relations Definition: A binary relation R from a set A to a set B is a subset R ⊆ A × B. Example: Let A = { 0, 1,2 } and B = {a,b} {( 0, a), (
1 A well-parenthesized string is a string with the same number of (‘s as )’s which has the property that every prefix of the string has at least as many.
Regular Expressions CS 130: Theory of Computation HMU textbook, Chapter 3.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
Lecture 02: Theory of Automata:2014 Asif Nawaz Theory of Automata.
Lecture 03: Theory of Automata:2014 Asif Nawaz Theory of Automata.
CHAPTER TWO LANGUAGES By Dr Zalmiyah Zakaria.
MA/CSSE 474 Theory of Computation Regular Expressions Intro.
Chapter 2. Formal Languages Dept. of Computer Engineering, Hansung University, Sung-Dong Kim.
Theory of Computation Lecture #
LANGUAGES Prepared by: Paridah Samsuri Dept. of Software Engineering
REGULAR LANGUAGES AND REGULAR GRAMMARS
Specifying Languages Our aim is to be able to specify languages for use in the computer. The sketch of the FSA is easy for us to understand, but difficult.
CSE322 Regular Expressions and their Identities
Chapter 1 Introduction to the Theory of Computation
CSC312 Automata Theory Lecture # 2 Languages.
Presentation transcript:

Chapter 2 Languages

Languages Defn. A language is a set of strings over an alphabet. A more restricted definition requires some forms of restrictions on the strings, i.e., strings that satisfy certain properties Defn. The syntax of a language restricts the set of strings that satisfy certain properties.

Languages Defn. A string over an alphabet X, denoted , is a finite sequence of elements from X, which are indivisible objects e.g., Strings can be words in English The set of strings over an alphabet is defined recursively (as given below)

Languages (i) Basis:   *, the null string Defn. 2.1.1. Let  be an alphabet. *, the set of strings over , is defined recursively as follows: (i) Basis:   *, the null string (ii) Recursion: w  *, a    wa  * (iii) Closure: w  * is obtained by step (i) and a finite # of step (ii) The length of a string w is denoted length(w) Q: If  contains n elements, how many possible strings over  are of length k ( *)?

Languages Example: Given  = {a, b}, * includes , a, b, aa, ab, ba, bb, aaa, … Defn 2.1.2. A language over an alphabet  is a subset of *. Defn 2.1.3. Concatenation, is the fundamental binary operation in the generation of strings, which is associative, but not commutative, is defined as Basis: If length(v) = 0, then v =  and uv = u Recursion: Let v be a string with length(v) = n (> 0). Then v = wa, for string w with length n-1 and a  , and uv = (uw)a

Languages Example: Let  = ab,  = cd, and  = e () = (), but   , Exponents are used to abbreviate the concatenation of a string with itself, denoted un (n  0) Defn 2.1.5. Reversal, which is a unary operation, rewrites a string backward, is defined as i) Basis: If length(u) = 0, then u =  and R = . ii) Recursion: If length(u) = n (> 0), then u = wa for some string w with length n - 1 and some a  , and uR = awR Theorem 2.1.6. let u, v  *. Then, (uv)R = vRuR. unless  = ,  = , or  = .

Languages Finite language specification Example 2.2.1. The language L of string over {a, b} in which each string begins with an ‘a’ and has even length. i) Basis: aa, ab  L. ii) Recursion: If u  L, iii) Closure: u  L only if u is obtained from the basis elements by a finite number of applications of the recursive step. Use set operations to construct complex sets of strings. Defn 2.2.1. The concatenation of languages X and Y, denoted XY, is the language XY = { uv | u  X and v  Y } Given a set X, X* denotes the set of strings that can be defined with  and  then uaa, uab, uba, ubb  L.

Languages X* = and X+ = U U  X i  X i Defn 2.2.2. let X be a set. Then X* = and X+ = X+ = XX* or X+ = X* - {  } Observation: Formal (i) recursive definitions, (ii) concatenation, and (iii) set operations precisely define languages, which require the unambiguous specification of the strings that belong to the language.  i=0 X i U  i=1 X i U

Regular Sets and Expressions Defn 2.3.1 Let  be an alphabet. The regular sets over  are defined recursively as follows: (i) Basis: , {  }, and { a }, a, are regular sets over . (ii) Recursion: Let X and Y be regular sets over . The sets X  Y, XY and X* are regular sets over . (iii) Closure: Any regular set over  is obtained from (i) and by a finite number of applications of (ii). Example: Describe the content of each of the following regular sets: (i) { aa }*, Regular expressions are used to abbreviate the descriptions of regular sets, e.g., replacing { b } by b, union () by (,), etc. (ii) { a }*  { b }*, (iii) ({a}  {b})*, (iv) { a } ({b}{c})*

L = {{a}  {b}}*{a}{a}{{a}  {b}}*  {{a}  {b}}*{b}{b}{{a}  {b}}* Languages Examples. (a) The set of strings over { a, b } that contains the substrings aa or bb L = {{a}  {b}}*{a}{a}{{a}  {b}}*  {{a}  {b}}*{b}{b}{{a}  {b}}* (b) The set of string over { a, b } that do not contain the substrings aa and bb L = (a, b)* - ((a, b)*aa(a, b)*  (a, b)*bb(a, b)*) [non-regular set] (c) The set of strings over {a, b} that contain exactly two b’s L = {a}*{b}{a}*{b}{a}*

Regular Sets and Expressions Defn 2.3.2. let  be an alphabet. The regular expressions over  are defined recursively as follows: (i) Basis: , , and a, a  , are regular expressions over . (ii) Recursion: Let u and v be regular expressions over . Then (u, v), (uv) and (u)* are regular expressions over . (iii) Closure: Any regular expression over  is obtained form (i) and by a finite number of applications of (ii). It is assumed that the following precedence is assigned to the operators to reduce the number of parentheses: *, , 

Regular Sets and Expressions Example: Give a regular expression for each of the following over the alphabet { 0, 1 }: { w | w begins with a ‘1’ and ends with a ‘0’ } { w | w contains at least three 1’s} { w | w is any string without the substring ‘11’ } { w | w is a string that begin with a ‘1’ and contain exactly two 0’s } { w | w contains an even number of 0’s, or contains exactly two 1’s and nothing else } Regular expression definition of a language is not unique.

Regular Expression Identities TABLE 2.1 Regular Expression Identities 1. u = u =  2. u = u = u 3. * =  4. * =  5. u  v = v  u 6 u   = u 7. u  u = u 8. u* = (u*)* 9. u (v  w) = uv  uw 10. (u  v) w = uw  vw 11. (uv)*u = u (vu)* 12. (u  v)* = (u*  v)* = u* (u  v)* = (u  vu*)* = (u*v*)* = u* (vu*)* = (u*v)* u*

Regular Expressions There exist non-regular expressions such as {anbn | n  0} {(0, 1)*(01)n(0, 1)*(10)n(0,1)*1 | n  0} Table 2.1 Regular Expression Identities * = ; The * operation puts together any number of strings from the language to get a (new) string in the result. If the language is empty, the * operation can put together 0 strings, giving only the null string ().  u = u  = ; Concatenating  to any set yields . (a, )(b, ) = {, a, b, ab}. The regular expression c*(b, ac*)* yields all strings that do not contain the substring bc. How about c*(b, ac*)*?

Grammars Languages and Accepting Machines Grammars Languages Accepting Machines Type 0 grammars, Recursively TM Phrase-structure grammars, enumerable NDTM Unrestricted grammars Unrestricted Type 1 grammars, Contest-sensitive Linear-bounded Context-sensitive grammars, languages Automata Monotonic grammars Type 2 grammars, Context-free PDA Context-free grammars languages Type 3 grammars, Regular FSA Regular grammars, languages NDFA Left-linear grammars, Right-linear grammars