REGULAR LANGUAGES AND REGULAR GRAMMARS

Slides:



Advertisements
Similar presentations
4b Lexical analysis Finite Automata
Advertisements

1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 3 School of Innovation, Design and Engineering Mälardalen University 2012.
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture4: Regular Expressions Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state.
Fall 2006Costas Busch - RPI1 Regular Expressions.
1 Regular Expressions. 2 Regular expressions describe regular languages Example: describes the language.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Regular.
Fall 2004COMP 3351 Single Final State for NFA. Fall 2004COMP 3352 Any NFA can be converted to an equivalent NFA with a single final state.
1 Single Final State for NFAs and DFAs. 2 Observation Any Finite Automaton (NFA or DFA) can be converted to an equivalent NFA with a single final state.
79 Regular Expression Regular expressions over an alphabet  are defined recursively as follows. (1) Ø, which denotes the empty set, is a regular expression.
Topics Automata Theory Grammars and Languages Complexities
1 A Single Final State for Finite Accepters. 2 Observation Any Finite Accepter (NFA or DFA) can be converted to an equivalent NFA with a single final.
Fall 2004COMP 3351 Regular Expressions. Fall 2004COMP 3352 Regular Expressions Regular expressions describe regular languages Example: describes the language.
Regular Languages A language is regular over  if it can be built from ;, {  }, and { a } for every a 2 , using operators union ( [ ), concatenation.
Regular Expressions (RE) Empty set Φ A RE denotes the empty set Empty string λ A RE denotes the set {λ} Symbol a A RE denotes the set {a} Alternation M.
Finite-State Machines with No Output
Regular Expressions. Notation to specify a language –Declarative –Sort of like a programming language. Fundamental in some languages like perl and applications.
Theory of Languages and Automata
Theory of Computation, Feodor F. Dragan, Kent State University 1 Regular expressions: definition An algebraic equivalent to finite automata. We can build.
1 Regular Expressions. 2 Regular expressions describe regular languages Example: describes the language.
4b 4b Lexical analysis Finite Automata. Finite Automata (FA) FA also called Finite State Machine (FSM) –Abstract model of a computing entity. –Decides.
Regular Expressions Hopcroft, Motawi, Ullman, Chap 3.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
CSCI 2670 Introduction to Theory of Computing September 1, 2005.
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.
CHAPTER 1 Regular Languages
Lecture # 12. Nondeterministic Finite Automaton (NFA) Definition: An NFA is a TG with a unique start state and a property of having single letter as label.
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 3813: Introduction to Formal Languages and Automata
Mathematical Foundations of Computer Science Chapter 3: Regular Languages and Regular Grammars.
Algorithms for hard problems Automata and tree automata Juris Viksna, 2015.
1 Language Recognition (11.4) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch
CS 154 Formal Languages and Computability February 11 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
Conversions Regular Expression to FA FA to Regular Expression.
Regular Expressions CS 130: Theory of Computation HMU textbook, Chapter 3.
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 Introduction to the Theory of Computation Regular Expressions.
Regular Languages Chapter 1 Giorgi Japaridze Theory of Computability.
1 Section 11.2 Finite Automata Can a machine(i.e., algorithm) recognize a regular language? Yes! Deterministic Finite Automata A deterministic finite automaton.
Theory of Languages and Automata By: Mojtaba Khezrian.
Lecture # 8 (Transition Graphs). Example Consider the language L of strings, defined over Σ={a, b}, having (containing) triple a or triple b. Consider.
Theory of Languages and Automata By: Mojtaba Khezrian.
CONTEXT-FREE LANGUAGES
Context-Free Grammars: an overview
Lexical analysis Finite Automata
Non Deterministic Automata
PROPERTIES OF REGULAR LANGUAGES
Regular Expressions.
CS314 – Section 5 Recitation 3
Chapter 7 PUSHDOWN AUTOMATA.
Pushdown Automata Reading: Chapter 6.
Single Final State for NFA
Chapter 2 FINITE AUTOMATA.
Language Recognition (12.4)
Context-Free Languages
Chapter 7 Regular Grammars
CHAPTER 2 Context-Free Languages
Definitions Equivalence to Finite Automata
4b Lexical analysis Finite Automata
Chapter Five: Nondeterministic Finite Automata
4b Lexical analysis Finite Automata
Language Recognition (12.4)
CSC312 Automata Theory Transition Graphs Lecture # 9
Chapter 1 Regular Language
Finite-State Machines with No Output
NFAs and Transition Graphs
CSC312 Automata Theory Kleene’s Theorem Lecture # 12
Presentation transcript:

REGULAR LANGUAGES AND REGULAR GRAMMARS Chapter 3 REGULAR LANGUAGES AND REGULAR GRAMMARS

Learning Objectives At the conclusion of the chapter, the student will be able to: Identify the language associated with a regular expression Find a regular expression to describe a given language Construct a nondeterministic finite automaton to accept the language denoted by a regular expression Use generalized transition graphs to construct a regular expression that denotes the language accepted by a given finite automaton Identify whether a particular grammar is regular Construct regular grammars for simple languages Construct a nfa that accepts the language generated by a regular grammar Construct a regular grammar that generates the language accepted by a finite automaton

Regular Expressions Regular Expressions provide a concise way to describe some languages Regular Expressions are defined recursively. For any alphabet: the empty set, the empty string, or any symbol from the alphabet are primitive regular expressions the union (+), concatenation (), and star closure (*) of regular expressions is also a regular expression any string resulting from a finite number of these operations on primitive regular expressions is also a regular expression

Languages Associated with Regular Expressions A regular expression r denotes a language L(r) Assuming that r1 and r2 are regular expressions: The regular expression  denotes the empty set The regular expression  denotes the set {  } For any a in the alphabet, the regular expression a denotes the set { a } The regular expression r1 + r2 denotes L(r1)  L(r2) The regular expression r1  r2 denotes L(r1) L(r2) The regular expression (r1) denotes L(r1) The regular expression r1* denotes (L(r1))*

Determining the Language Denoted by a Regular Expression By combining regular expressions using the given rules, arbitrarily complex expressions can be constructed The concatenation symbol () is usually omitted In applying operations, we observe the following precedence rules: star closure precedes concatenation concatenation precedes union Parentheses are used to override the normal precedence of operators

Sample Regular Expressions and Associated Languages (ab)* { (ab)n, n ≥ 0 } a + b { a, b } (a + b)* { a, b }* (in other words, any string formed with a and b) a(bb)* { a, abb, abbbb, abbbbbb, … } a*(a + b) { a, aa, aaa, …, b, ab, aab, … } (Example 3.2) (aa)*(bb)*b { b, aab, aaaab, …, bbb, aabbb, … } (Example 3.4) (0 + 1)*00(0 + 1)* Binary strings containing at least one pair of consecutive zeros Two regular expressions are equivalent if they denote the same language. Consider, for example, (a + b)* and (a*b*)*

Regular Expressions and Regular Languages Theorem 3.1: For any regular expression r, there is a nondeterministic finite automaton that accepts the language denoted by r Since nondeterministic and deterministic accepters are equivalent, regular expressions are associated precisely with regular languages A constructive proof of theorem 3.1 provides a systematic procedure for constructing a nfa that accepts the language denoted by any regular expression

Construction of a nondeterministic fa to accept a language L(r) We can construct simple automata that accept the languages associated with the empty set, the empty string, and any individual symbol.

Construction of a nondeterministic fa to accept a language L(r) (cont Given schematic representations for automata designed to accept L(r1) and (r2), an automaton to accept L(r1 + r2) can be constructed as shown in Figure 3.3

Construction of a nondeterministic fa to accept a language L(r) (cont Given schematic representations for automata designed to accept L(r1) and (r2), an automaton to accept L(r1r2) can be constructed as shown in Figure 3.4

Construction of a nondeterministic fa to accept a language L(r) (cont Given a schematic representation for an automaton designed to accept L(r1), an automaton to accept L(r1*) can be constructed as shown in Figure 3.5

Example: Construction of a nfa to accept a language L(r) Given the regular expression r = (a + bb)* (ba* + ), a nondeterministic fa to accept L(r) can be constructed systematically as shown in Figure 3.7

Regular Expressions for Regular Languages Theorem 3.2: For every regular language, it is possible to construct a corresponding r.e. The process can be illustrated with a generalized transition graph (GTG) A GTG for L(a* + a*(a + b)c*) is shown below

Regular Grammars In a right-linear grammar, at most one variable symbol appears on the right side of any production. If it occurs, it is the rightmost symbol. In a left-linear grammar, at most one variable symbol appears on the right side of any production. If it occurs, it is the leftmost symbol. A regular grammar is either right-linear or left-linear. Example 3.13 presents a regular (right-linear) grammar: V = { S }, T = { a, b }, and productions S  abS | a

Right-Linear Grammars Generate Regular Languages Per theorem 3.3, it is always possible to construct a nfa to accept the language generated by a regular grammar G: Label the nfa start state with S and a final state Vf For every variable symbol Vi in G, create a nfa state and label it Vi For each production of the form A → aB , label a transition from state A to B with symbol a For each production of the form A → a, label a transition from state A to Vf with symbol a (may have to add intermediate states for productions with more than one terminal on RHS)

Example: Construction of a nfa to accept a language L(G) Given the regular grammar G with productions V0  aV1 V1  abV0 | b a nondeterministic fa to accept L(G) can be constructed systematically as shown in Figure 3.17

Right-Linear Grammars for Regular Languages Per theorem 3.4, it is always possible to construct a regular grammar G to generate the language accepted by a dfa M: Each state in the dfa corresponds to a variable symbol in G For each dfa transition from state A to state B labeled with symbol a, there is a production of the form A → aB in G For each final state Fi in the dfa, there is a corresponding production Fi → λ in G

Example: Construction of a regular grammar G to generate a language L(M) Given the language L(aab*a), Figure 3.18 shows the transition function for a dfa that accepts the language and the productions for the corresponding regular grammar.

Equivalence of Regular Languages and Regular Grammars