Regular Languages Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Translators.

Slides:



Advertisements
Similar presentations
4b Lexical analysis Finite Automata
Advertisements

Theory Of Automata By Dr. MM Alam
Context Free Grammars.
Finite Automata Finite-state machine with no output. FA consists of States, Transitions between states FA is a 5-tuple Example! A string x is recognized.
1 Grammars. 2 Grammars express languages Example: the English language.
1 Reverse of a Regular Language. 2 Theorem: The reverse of a regular language is a regular language Proof idea: Construct NFA that accepts : invert the.
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
Finite Automata Chapter 5. Formal Language Definitions Why need formal definitions of language –Define a precise, unambiguous and uniform interpretation.
COP4020 Programming Languages
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.
Grammars, Languages and Finite-state automata Languages are described by grammars We need an algorithm that takes as input grammar sentence And gives a.
Finite State Machines Data Structures and Algorithms for Information Processing 1.
Finite-State Machines with No Output
::ICS 804:: Theory of Computation - Ibrahim Otieno SCI/ICT Building Rm. G15.
1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.
Theory of Languages and Automata
1 Regular Expressions. 2 Regular expressions describe regular languages Example: describes the language.
Context Free Grammars CIS 361. Introduction Finite Automata accept all regular languages and only regular languages Many simple languages are non regular:
Chapter 5 Context-Free Grammars
Grammars CPSC 5135.
Languages & Grammars. Grammars  A set of rules which govern the structure of a language Fritz Fritz The dog The dog ate ate left left.
1 Computability Five lectures. Slides available from my web page There is some formality, but it is gentle,
Introduction to Language Theory
Regular Expressions Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Translators.
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.
CS 321 Programming Languages and Compilers Lectures 16 & 17 Introduction to Formal Languages Regular Languages Lexical Analysis.
 Regular Grammar and Regular Language [Def 3.1] Regular Grammar(use to in lexical analysis) Type 3 grammar(regular grammar, RG) Type 3 grammar(regular.
Overview of Previous Lesson(s) Over View  Symbol tables are data structures that are used by compilers to hold information about source-program constructs.
CS 3813: Introduction to Formal Languages and Automata
Recognising Languages We will tackle the problem of defining languages by considering how we could recognise them. Problem: Is there a method of recognising.
1 Chapter 6 Simplification of CFGs and Normal Forms.
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.
Introduction Finite Automata accept all regular languages and only regular languages Even very simple languages are non regular (  = {a,b}): - {a n b.
Three Basic Concepts Languages Grammars Automata.
Regular Grammars Reading: 3.3. What we know so far…  FSA = Regular Language  Regular Expression describes a Regular Language  Every Regular Language.
R. Johnsonbaugh Discrete Mathematics 5 th edition, 2001 Chapter 10 Automata, Grammars and Languages.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2007.
Mathematical Foundations of Computer Science Chapter 3: Regular Languages and Regular Grammars.
Chapter 4: Syntax analysis Syntax analysis is done by the parser. –Detects whether the program is written following the grammar rules and reports syntax.
Transparency No. 1 Formal Language and Automata Theory Homework 5.
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.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2006.
1 Section 11.2 Finite Automata Can a machine(i.e., algorithm) recognize a regular language? Yes! Deterministic Finite Automata A deterministic finite automaton.
1 Chapter Pushdown Automata. 2 Section 12.2 Pushdown Automata A pushdown automaton (PDA) is a finite automaton with a stack that has stack operations.
Akram Salah ISSR Basic Concepts Languages Grammar Automata (Automaton)
1 Section 12.2 Pushdown Automata A pushdown automaton (PDA) is a finite automaton with a stack that has stack operations pop, push, and nop. PDAs always.
Theory of Languages and Automata By: Mojtaba Khezrian.
Week 14 - Wednesday.  What did we talk about last time?  Exam 3 post mortem  Finite state automata  Equivalence with regular expressions.
Lecture 11  2004 SDU Lecture7 Pushdown Automaton.
Chapter 2. Formal Languages Dept. of Computer Engineering, Hansung University, Sung-Dong Kim.
Theory of Computation Automata Theory Dr. Ayman Srour.
Theory of Languages and Automata By: Mojtaba Khezrian.
FINITE-STATE AUTOMATA COP4620 – Programming Language Translators Dr. Manuel E. Bermudez.
COP4620 – Programming Language Translators Dr. Manuel E. Bermudez
COP4620 – Programming Language Translators Dr. Manuel E. Bermudez
Formal Language & Automata Theory
Complexity and Computability Theory I
PARSE TREES.
Finite-state automata
Regular grammars Module 04.1 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Language Recognition (12.4)
REGULAR LANGUAGES AND REGULAR GRAMMARS
Regular expressions Module 04.3 COP4020 – Programing Language Concepts Dr. Manuel E. Bermudez.
COP4620 – Programming Language Translators Dr. Manuel E. Bermudez
Programming Language Concepts
Language Recognition (12.4)
LECTURE # 07.
Presentation transcript:

Regular Languages Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Translators

Regular Languages We will study: Regular grammars Relation to finite-state automata Regular expressions Equivalence among representations Elimination on non-determinism State minimization

Regular Languages Definition: A grammar G = (Φ, Σ, P, S) is regular iff either (but not both): Every production is of the form A →  or A → B (right linear) Every production is of the form A →  or A → B (left linear), where   Σ*, and A, B  Φ.

Regular Languages Examples: G1: S → a R → abaU → bU → U Regular? Why? → bRU → b → S G2: S → aR → Uaba → UbU → b Regular? Why? → Rb → aS

Regular Languages Let’s devise a machine that accepts L(G1). Observe that S => a bU => bb … bR bS … babaU 1.Every sentential form (except sentences) has exactly one nonterminal. 2.The nonterminal occurs in the right-most position. 3.Applicable productions depend only on that nonterminal. =>

Regular Languages Encode possible derivation sequences with a relation ⊢ on pairs of the form (q, ), where q – current state  – remaining string to accept So, S → bU implies (S, bβ) ⊢ (U, β) State “sentential form ends in S” “moves to” state “sentential form ends in U”

Regular Languages Define a graph, one node per nonterminal, describing the possible actions on each sentential form. So, S → bU implies, R → U implies, S → a implies. SU RU SF b  a

Regular Languages Example: S → a R → abaUU → b → bU → U → aS → bR S U R F aba ε b b a b a

Regular Languages In general, Right-linear grammar → Transition diagram: 1.Nodes: Φ  {f}, f  Φ 2.if A →  B 3. if A →  4. AB S AF α α

Regular Languages Example: Is “babaa” in L(G)? NodeInputDerivation SbabaaS => U abaabU => S baabaS => U aababU => S ababaS => Fbabaa Yes.

Finite-State Automata Definition: A (non-deterministic) finite-state automaton is a 5-tuple M = (Q, Σ, δ, s, F), where Q is a finite set of states, Σ is a finite set of transition symbols, δ: Q x Σ  {ε} → 2 Q is a partial function called the transition function, s  Q is called the start state, and F  Q is the set of final states.

Finite-State Automata An FSA is the formal accepting mechanism of a regular language. It requires that each transition be labeled by a string of length < 1. The state diagram is described by the FSA S U R F aba ε b b a b a

Finite-State Automata ({S, R, U, F, X, Y}, {a, b}, δ, S, {F}), where δ (S, a) = {F} δ (S, b) = {U, R} δ (R, ε) = {U} δ (R, a) = {X} δ (U, a) = {S} δ (U, b) = {F} δ (X, b) = {Y} δ (Y, a) = {U} RX XY YU a b a

Finite-State Automata TWO “SYMPTOMS” OF NON-DETERMINISM: Note:is not a problem F a X a a X ε a 1. 2.

Finite-State Automata Advantages of FSA’s: Question: What language does the following grammar generate? S → aAA → aBB → aC → ε → E → D C → bDD → bEE → bS Difficult to see. Try FSA.

Finite-State Automata Answer: L*, where L = {ab, aabb, aaabbb} Summary: FSA’s are as powerful as right-linear regular grammars. Are they more powerful? No. Can transform FSA → RG R. F ε SA EDC B b ε b aa ε b a

Finite-State Automata Transition Diagram (FSA) → Right-linear regular grammar 1.Φ = Q 2.A → aBif B  δ (A, a) 3.A → aif f  δ (A, a), and f  F 4.Start symbol = Start state

Finite-State Automata Example: FSA: RGR:A → aBB → bBD → cE → a → bD → c → b E → FF → dGG → H → ε H → A Conclusion: Right-linear regular grammars and FSA’s are equivalent. A GF ε ε ba d H BDE b c ε

Finite-State Automata Relationship between Left-linear regular grammars and FSA’s: Example:F → SaU → SbR → Sb → Ub → RS → Ua → Raba → Derivations: Sbb... F => Ub => Rb... Rabab... Sa => Uaa... a =>

Finite-State Automata Similarities with right-linear grammars: 1.Sentential forms have at most one nonterminal. 2.Sentences have none. 3.Applicable productions depend only on the one nonterminal. Differences with right-linear grammars: 1.Nonterminals appears on left-most position. 2.String generated right-to-left, versus left-to-right for right-linear grammars.

Finite-State Automata Left-linear Regular Grammar → FSA 1. if A → B . 2. if A → , S’ is a new start state. 3.F = {S}, S is the start symbol. BA S’A α α

Finite-State Automata Example: F → SaU → SBS → Ua → Ub → R → ε R → Sb → Raba S U R F aba ε b b a b a S’ ε

Finite-State Automata StateInputDerivation S’babaaa babaaa SbabaaaSbabaaa <= R abaaa Rabaaa <= U aa Uaa <= S a Sa <= F

Finite-State Automata FSA → Left-linear Regular Grammar: 1.A → B  if 2.A →  if 3.S’ → F if BA SA α α F New start symbol

Finite-State Automata Summarizing: RG R RG L REFSA Note: Beware of attempts at direct conversion between left and right-linear grammars. Done Soon