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.

Slides:



Advertisements
Similar presentations
Grammar types There are 4 types of grammars according to the types of rules: – General grammars – Context Sensitive grammars – Context Free grammars –
Advertisements

CFGs and PDAs Sipser 2 (pages ). Long long ago…
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
The CYK Algorithm David Rodriguez-Velazquez CS – 6800 Summer I
CFGs and PDAs Sipser 2 (pages ). Last time…
CS5371 Theory of Computation
Theory of Computation What types of things are computable? How can we demonstrate what things are computable?
1 Regular Grammars Generate Regular Languages. 2 Theorem Regular grammars generate exactly the class of regular languages: If is a regular grammar then.
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.
Finite Automata Chapter 5. Formal Language Definitions Why need formal definitions of language –Define a precise, unambiguous and uniform interpretation.
Prof. Busch - LSU1 Linear Grammars Grammars with at most one variable at the right side of a production Examples:
Languages and Grammars MSU CSE 260. Outline Introduction: E xample Phrase-Structure Grammars: Terminology, Definition, Derivation, Language of a Grammar,
Fall 2003Costas Busch - RPI1 Linear Grammars Grammars with at most one variable at the right side of a production Examples:
Problem of the DAY Create a regular context-free grammar that generates L= {w  {a,b}* : the number of a’s in w is not divisible by 3} Hint: start by designing.
Formal Grammars Denning, Sections 3.3 to 3.6. Formal Grammar, Defined A formal grammar G is a four-tuple G = (N,T,P,  ), where N is a finite nonempty.
Finite-State Machines with No Output
Introduction Chapter 0. Three Central Areas 1.Automata 2.Computability 3.Complexity.
Context-Free Grammars Normal Forms Chapter 11. Normal Forms A normal form F for a set C of data objects is a form, i.e., a set of syntactically valid.
CSCI 2670 Introduction to Theory of Computing September 20, 2005.
1 Section 14.2 A Hierarchy of Languages Context-Sensitive Languages A context-sensitive grammar has productions of the form xAz  xyz, where A is a nonterminal.
1 Language Definitions Lecture # 2. Defining Languages The languages can be defined in different ways, such as Descriptive definition, Recursive definition,
Automata, Computability, & Complexity by Elaine Rich ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Slides provided by author Slides edited for.
Lecture # 3 Regular Expressions 1. Introduction In computing, a regular expression provides a concise and flexible means to "match" (specify and recognize)
Languages, Grammars, and Regular Expressions Chuck Cusack Based partly on Chapter 11 of “Discrete Mathematics and its Applications,” 5 th edition, by Kenneth.
Chapter 5 Context-Free Grammars
Grammars CPSC 5135.
Context Free Grammar. Introduction Why do we want to learn about Context Free Grammars?  Used in many parsers in compilers  Yet another compiler-compiler,
L ECTURE 3 Chapter 4 Regular Expressions. I MPORTANT T ERMS Regular Expressions Regular Languages Finite Representations.
Phrase-structure grammar A phrase-structure grammar is a quadruple G = (V, T, P, S) where V is a finite set of symbols called nonterminals, T is a set.
Grammar G = (V N, V T, P, S) –V N : Nonterminal symbols –V T : Terminal symbols V N  V T = , V N ∪ V T = V – P : a finite set of production rules α 
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.
Context Free Grammars.
Regular Expressions Chapter 6 1. Regular Languages Regular Language Regular Expression Finite State Machine L Accepts 2.
Strings and Languages CS 130: Theory of Computation HMU textbook, Chapter 1 (Sec 1.5)
Copyright © Curt Hill Finite State Automata Again This Time No Output.
Regular Expressions Chapter 6. Regular Languages Regular Language Regular Expression Finite State Machine Recognizes or Accepts Generates.
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.
1 Simplification of Context-Free Grammars Some useful substitution rules. Removing useless productions. Removing -productions. Removing unit-productions.
Chapter 6 Properties of Regular Languages. 2 Regular Sets and Languages  Claim(1). The family of languages accepted by FSAs consists of precisely the.
Regular Expressions Chapter 6. Regular Languages Regular Language Regular Expression Finite State Machine L Accepts.
CS 3813: Introduction to Formal Languages and Automata
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.
Regular Grammars Reading: 3.3. What we know so far…  FSA = Regular Language  Regular Expression describes a Regular Language  Every Regular Language.
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
Costas Busch - LSU1 Linear Grammars Grammars with at most one variable at the right side of a production Examples:
Unrestricted Grammars
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.
Lecture 17: Theory of Automata:2014 Context Free Grammars.
PROGRAMMING LANGUAGES
CS314 – Section 5 Recitation 2
BCT 2083 DISCRETE STRUCTURE AND APPLICATIONS
Regular Languages, Regular Operations, Closure
David Rodriguez-Velazquez CS – 6800 Summer I
Theory of Languages and Automata
Complexity and Computability Theory I
Natural Language Processing - Formal Language -
CSC312 Automata Theory Grammatical Format Chapter # 13 by Cohen
CS314 – Section 5 Recitation 3
Language Recognition (12.4)
REGULAR LANGUAGES AND REGULAR GRAMMARS
Regular Grammar.
Regular Grammars.
Chapter 7 Regular Grammars
Language Recognition (12.4)
Regular Grammars.
Presentation transcript:

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 and terminals, ●  (the set of terminals) is a subset of V, ● R (the set of rules) is a finite set of rules of the form: X  Y, ● S (the start symbol) is a nonterminal.

Regular Grammars In a regular grammar, all rules in R must: ● have a left hand side that is a single nonterminal ● have a right hand side that is: ● , or ● a single terminal, or ● a single terminal followed by a single nonterminal. Legal: S  a, S  , and T  a S Not legal: S  a S a and a S a  T

Regular Grammar Example L = {w  { a, b }* : |w| is even} (( aa )  ( ab )  ( ba )  ( bb ))*

Regular Grammar Example L = {w  { a, b }* : |w| is even} (( aa )  ( ab )  ( ba )  ( bb ))* S   S  a T S  b T T  a T  b T  a S T  b S

Regular Languages and Regular Grammars Theorem: The class of languages that can be defined with regular grammars is exactly the regular languages. Proof: By two constructions.

Regular Languages and Regular Grammars Regular grammar  FSM: grammartofsm(G = (V, , R, S)) = 1. Create in M a separate state for each nonterminal in V. 2. Start state is the state corresponding to S. 3. If there are any rules in R of the form X  w, for some w  , create a new state labeled #. 4. For each rule of the form X  w Y, add a transition from X to Y labeled w. 5. For each rule of the form X  w, add a transition from X to # labeled w. 6. For each rule of the form X  , mark state X as accepting. 7. Mark state # as accepting. FSM  Regular grammar: Similarly.

Example 1 - Even Length Strings S   T  a S  a T T  b S  b T T  a S T  b S

Strings that End with aaaa L = {w  { a, b }* : w ends with the pattern aaaa }. S  a S S  b S S  a B B  a C C  a D D  a

Strings that End with aaaa L = {w  { a, b }* : w ends with the pattern aaaa }. S  a S S  b S S  a B B  a C C  a D D  a

Example 2 – One Character Missing S   A  bAC  aCS  aBA  cAC  bCS  aC A  C  S  bA B  aBS  bC B  cBS  cA B  S  cBS   A  bAC  aCS  aBA  cAC  bCS  aC A  C  S  bA B  aBS  bC B  cBS  cA B  S  cB