Costas Busch - RPI1 Grammars. Costas Busch - RPI2 Grammars Grammars express languages Example: the English language.

Slides:



Advertisements
Similar presentations
1 Context-Free Languages. 2 Regular Languages 3 Context-Free Languages.
Advertisements

Grammars, constituency and order A grammar describes the legal strings of a language in terms of constituency and order. For example, a grammar for a fragment.
Fall 2006Costas Busch - RPI1 Non-regular languages (Pumping Lemma)
Prof. Busch - LSU1 Simplifications of Context-Free Grammars.
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.
Courtesy Costas Busch - RPI1 More Applications of the Pumping Lemma.
Courtesy Costas Busch - RPI1 Non Deterministic Automata.
Fall 2006Costas Busch - RPI1 Regular Expressions.
Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
Costas Busch - RPI1 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars.
Courtesy Costas Busch - RPI1 NPDAs Accept Context-Free Languages.
Costas Buch - RPI1 Simplifications of Context-Free Grammars.
Fall 2006Costas Busch - RPI1 The Post Correspondence Problem.
Courtesy Costas Busch - RPI
1 Grammars. 2 Grammars express languages Example: the English language.
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.
1 Regular Grammars Generate Regular Languages. 2 Theorem Regular grammars generate exactly the class of regular languages: If is a regular grammar then.
Costas Busch - RPI1 The Pumping Lemma for Context-Free Languages.
Fall 2006Costas Busch - RPI1 Properties of Regular Languages.
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.
Courtesy Costas Busch - RPI1 Non-regular languages.
Fall 2006Costas Busch - RPI1 Non-Deterministic Finite Automata.
Fall 2006Costas Busch - RPI1 More Applications of the Pumping Lemma.
COP4020 Programming Languages
Fall 2006Costas Busch - RPI1 PDAs Accept Context-Free Languages.
Prof. Busch - LSU1 Linear Grammars Grammars with at most one variable at the right side of a production Examples:
Prof. Busch - LSU1 Context-Free Languages. Prof. Busch - LSU2 Regular Languages Context-Free Languages.
Fall 2005Costas Busch - RPI1 Context-Free Languages.
Fall 2004COMP 3351 Regular Expressions. Fall 2004COMP 3352 Regular Expressions Regular expressions describe regular languages Example: describes the language.
Fall 2003Costas Busch - RPI1 Linear Grammars Grammars with at most one variable at the right side of a production Examples:
Context-Free Languages Hinrich Schütze CIS, LMU, Slides based on RPI CSCI 2400 Thanks to Costas Busch.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 7 Mälardalen University 2010.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 5 Mälardalen University 2005.
Theory of Languages and Automata
1 Regular Expressions. 2 Regular expressions describe regular languages Example: describes the language.
1 Context-Free Languages. 2 Regular Languages 3 Context-Free Languages.
1 Context-Free Languages. 2 Regular Languages 3 Context-Free Languages.
Conversions & Pumping Lemma CPSC 388 Fall 2001 Ellen Walker Hiram College.
Regular Expressions Costas Busch - LSU.
Lecture 8 Context-Free Grammar- Cont.
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.
1 Context-Free Languages. 2 Regular Languages 3 Context-Free Languages.
Regular Grammars Reading: 3.3. What we know so far…  FSA = Regular Language  Regular Expression describes a Regular Language  Every Regular Language.
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.
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:
Costas Busch - LSU1 The Post Correspondence Problem.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2006.
Costas Busch - LSU1 PDAs Accept Context-Free Languages.
1 Linear Grammars Grammars with at most one variable at the right side of a production Examples:
Non-regular languages
Standard Representations of Regular Languages
PDAs Accept Context-Free Languages
Reductions Costas Busch - LSU.
NPDAs Accept Context-Free Languages
Simplifications of Context-Free Grammars
NPDAs Accept Context-Free Languages
Language Recognition (12.4)
CSE322 LEFT & RIGHT LINEAR REGULAR GRAMMAR
DPDA Deterministic PDA
Regular Grammar.
More NP-complete Problems
Non-Deterministic Finite Automata
The Post Correspondence Problem
Elementary Questions about Regular Languages
Non-regular languages
Properties of Context-Free languages
Language Recognition (12.4)
DPDA Deterministic PDA
Presentation transcript:

Costas Busch - RPI1 Grammars

Costas Busch - RPI2 Grammars Grammars express languages Example: the English language

Costas Busch - RPI3

4 A derivation of “the dog walks”:

Costas Busch - RPI5 A derivation of “a cat runs”:

Costas Busch - RPI6 Language of the grammar: L = { “a cat runs”, “a cat walks”, “the cat runs”, “the cat walks”, “a dog runs”, “a dog walks”, “the dog runs”, “the dog walks” }

Costas Busch - RPI7 Notation VariableTerminal Production Rules

Costas Busch - RPI8 Another Example Grammar: Derivation of sentence :

Costas Busch - RPI9 Grammar: Derivation of sentence :

Costas Busch - RPI10 Other derivations:

Costas Busch - RPI11 Language of the grammar

Costas Busch - RPI12 More Notation Grammar Set of variables Set of terminal symbols Start variable Set of Production rules

Costas Busch - RPI13 Example Grammar :

Costas Busch - RPI14 More Notation Sentential Form: A sentence that contains variables and terminals Example: Sentential Formssentence

Costas Busch - RPI15 We write: Instead of:

Costas Busch - RPI16 In general we write: If:

Costas Busch - RPI17 By default:

Costas Busch - RPI18 Example Grammar Derivations

Costas Busch - RPI19 Grammar Example Derivations

Costas Busch - RPI20 Another Grammar Example Grammar : Derivations:

Costas Busch - RPI21 More Derivations

Costas Busch - RPI22 Language of a Grammar For a grammar with start variable : String of terminals

Costas Busch - RPI23 Example For grammar : Since:

Costas Busch - RPI24 A Convenient Notation

Costas Busch - RPI25 Linear Grammars

Costas Busch - RPI26 Linear Grammars Grammars with at most one variable at the right side of a production Examples:

Costas Busch - RPI27 A Non-Linear Grammar Grammar : Number of in string

Costas Busch - RPI28 Another Linear Grammar Grammar :

Costas Busch - RPI29 Right-Linear Grammars All productions have form: Example: or string of terminals

Costas Busch - RPI30 Left-Linear Grammars All productions have form: Example: or string of terminals

Costas Busch - RPI31 Regular Grammars

Costas Busch - RPI32 Regular Grammars A regular grammar is any right-linear or left-linear grammar Examples:

Costas Busch - RPI33 Observation Regular grammars generate regular languages Examples:

Costas Busch - RPI34 Regular Grammars Generate Regular Languages

Costas Busch - RPI35 Theorem Languages Generated by Regular Grammars Regular Languages

Costas Busch - RPI36 Theorem - Part 1 Languages Generated by Regular Grammars Regular Languages Any regular grammar generates a regular language

Costas Busch - RPI37 Theorem - Part 2 Languages Generated by Regular Grammars Regular Languages Any regular language is generated by a regular grammar

Costas Busch - RPI38 Proof – Part 1 Languages Generated by Regular Grammars Regular Languages The language generated by any regular grammar is regular

Costas Busch - RPI39 The case of Right-Linear Grammars Let be a right-linear grammar We will prove: is regular Proof idea: We will construct NFA with

Costas Busch - RPI40 Grammar is right-linear Example:

Costas Busch - RPI41 Construct NFA such that every state is a grammar variable: special final state

Costas Busch - RPI42 Add edges for each production:

Costas Busch - RPI43

Costas Busch - RPI44

Costas Busch - RPI45

Costas Busch - RPI46

Costas Busch - RPI47

Costas Busch - RPI48 Grammar NFA

Costas Busch - RPI49 In General A right-linear grammar has variables: and productions: or

Costas Busch - RPI50 We construct the NFA such that: each variable corresponds to a node: special final state

Costas Busch - RPI51 For each production: we add transitions and intermediate nodes ………

Costas Busch - RPI52 For each production: we add transitions and intermediate nodes ………

Costas Busch - RPI53 Resulting NFA looks like this: It holds that:

Costas Busch - RPI54 The case of Left-Linear Grammars Let be a left-linear grammar We will prove: is regular Proof idea: We will construct a right-linear grammar with

Costas Busch - RPI55 Since is left-linear grammar the productions look like:

Costas Busch - RPI56 Construct right-linear grammar Left linear Right linear

Costas Busch - RPI57 Construct right-linear grammar Left linear Right linear

Costas Busch - RPI58 It is easy to see that: Since is right-linear, we have: Regular Language Regular Language Regular Language

Costas Busch - RPI59 Proof - Part 2 Languages Generated by Regular Grammars Regular Languages Any regular language is generated by some regular grammar

Costas Busch - RPI60 Proof idea: Let be the NFA with. Construct from a regular grammar such that Any regular language is generated by some regular grammar

Costas Busch - RPI61 Since is regular there is an NFA such that Example:

Costas Busch - RPI62 Convert to a right-linear grammar

Costas Busch - RPI63

Costas Busch - RPI64

Costas Busch - RPI65

Costas Busch - RPI66 In General For any transition: Add production: variableterminalvariable

Costas Busch - RPI67 For any final state: Add production:

Costas Busch - RPI68 Since is right-linear grammar is also a regular grammar with