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.

Slides:



Advertisements
Similar presentations
Context free languages 1. Equivalence of context free grammars 2. Normal forms.
Advertisements

101 The Cocke-Kasami-Younger Algorithm An example of bottom-up parsing, for CFG in Chomsky normal form G :S  AB | BB A  CC | AB | a B  BB | CA | b C.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
Conversion of a Chomsky normal form grammar to Greibach normal form
The CYK Algorithm David Rodriguez-Velazquez CS – 6800 Summer I
Chapter 4 Normal Forms for CFGs Chomsky Normal Form n Defn A CFG G = (V, , P, S) is in chomsky normal form if each rule in G has one of.
Traveling Salesman Problems Repetitive Nearest-Neighbor and Cheapest-Link Algorithms Chapter: 6.
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.
Languages and Grammars MSU CSE 260. Outline Introduction: E xample Phrase-Structure Grammars: Terminology, Definition, Derivation, Language of a Grammar,
Chapter 12: Context-Free Languages and Pushdown Automata
Chapter 2 Languages.
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.
BİL 744 Derleyici Gerçekleştirimi (Compiler Design)1 Syntax Analyzer Syntax Analyzer creates the syntactic structure of the given source program. This.
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.
Normal Forms for Context-Free Grammars Definition: A symbol X in V  T is useless in a CFG G=(V, T, P, S) if there does not exist a derivation of the form.
1 Language Definitions Lecture # 2. Defining Languages The languages can be defined in different ways, such as Descriptive definition, Recursive definition,
Languages, Grammars, and Regular Expressions Chuck Cusack Based partly on Chapter 11 of “Discrete Mathematics and its Applications,” 5 th edition, by Kenneth.
Classification of grammars Definition: A grammar G is said to be 1)Right-linear if each production in P is of the form A  xB or A  x where A and B are.
Chapter 5 Context-Free Grammars
Context Free Grammar. Introduction Why do we want to learn about Context Free Grammars?  Used in many parsers in compilers  Yet another compiler-compiler,
Introduction to Language Theory
Membership problem CYK Algorithm Project presentation CS 5800 Spring 2013 Professor : Dr. Elise de Doncker Presented by : Savitha parur venkitachalam.
Computing the chromatic number for block intersection graphs of Latin squares Ed Sykes CS 721 project McMaster University, December 2004 Slide 1.
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.
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 α 
CFG1 CSC 4181Compiler Construction Context-Free Grammars Using grammars in parsers.
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.
Section 12.4 Context-Free Language Topics
Objective: Students will use proportional parts of triangles and divide a segment into parts. S. Calahan 2008.
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.
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.
January 20, 2016CS21 Lecture 71 CS21 Decidability and Tractability Lecture 7 January 20, 2016.
Formal Languages and Grammars
Mathematical Foundations of Computer Science Chapter 3: Regular Languages and Regular Grammars.
Transparency No. 1 Formal Language and Automata Theory Homework 5.
Chomsky Normal Form.
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.
20 G M aaba acba aaba.. What is it about? Models of Language Generation Models of Language Recognition.
Learning from Bare Bones
lec02-parserCFG May 8, 2018 Syntax Analyzer
David Rodriguez-Velazquez CS – 6800 Summer I
Complexity and Computability Theory I
Natural Language Processing - Formal Language -
Context-Free Grammars
PROPORTIONAL SEGMENTS & BASIC SIMILARITY THEOREM
Combinations COURSE 3 LESSON 11-3
Context-Free Grammars
Make an Organized List and Simulate a Problem
تصنيف التفاعلات الكيميائية
Context-Free Grammars
Chapter 7 Regular Grammars
Chapter 6 Simplification of Context-free Grammars and Normal Forms
Splash Screen.
Splash Screen.
Context-Free Grammars
A Series of Slides in 5 Parts Movement 2. BFS
Splash Screen.
The Cocke-Kasami-Younger Algorithm
Regular Grammars.
lec02-parserCFG May 27, 2019 Syntax Analyzer
Context-Free Grammars
A Series of Slides in 5 Parts Movement 4. Best-First
A Series of Slides in 5 Parts Movement 4. Best-First
A Series of Slides in 5 Parts Movement 1. DFS
A Series of Slides in 5 Parts Movement 3. IDFS
Presentation transcript:

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 of terminals, P is the set of productions  → ,   (V  T)*V(V  T)*,   (V  T)*, S is a member of V called the start symbol.

S → ABC AB → aAD AB → bAE DC → BaC EC → BbC Da → aD Db → bD Ea → aE Eb → bE AB →  C →  aB → Ba bB → Bb

Context-sensitive Grammar Definition: A grammar G = (V, T, P, S) is context sensitive if |  |  |  | for every production  in P. Definition: A “true” context sensitive grammar G = (V, T, P, S) is a grammar in which each production is of the form  A   , where  and  are in (V  T) *,  in (V  T) +, and A in V. The production  A    is also written as A   /  _ 

Example: S  ABC S  ABCS AB  BA AC  CA BC  CB BA  AB CA  AC CB  BC A  a B  b C  c

1)S  ASCB 2)S  ACB 3)CB  CR 4)CR  BR 5)BR  BC 6)AB  Ab 7)Ab  ab 8)Aa  aa 9)bB  bb 10)bC  bc 11)cC  cc

Definition: A language L is context- sensitive language if it is generated by a context-sensitive grammar. Theorem: Every context-sensitive language can be generated by a true context-sensitive grammar.

Step 1: convert all rules of the grammar G to the form    where  is a string of non terminals, let G 1 be the new grammar replace a by N a and add a production N a  a, where N a is a new nonterminal Step 2: Let w(G) = max {|  |, where  is in P} Convert the grammar G 1 to a grammar G 2 such that   V + and w(G 2 )  2

Let  : A 1 …A m  B 1.. B n be a production If n  2, add it to G 2 If 2  m < n, create two productions: A 1 … A m  B 1 … B m-1 X X  B m … B n If m = 1 and n  3 create n-1 productions A 1  B 1 X 1 X 1  B 2 X 2 … X n-2  B n-1 B n

If m = n and n  3, create the n-1 productions A 1 A 2  B 1 X 1 X 1 A 3  B 2 X 2 … X n-2 A n  B n-1 B n Step 3: Convert G 2 to a new grammar G 3 Add productions of the form A   to G 3 If AB  CD is a production and if A= C or B = D, add to G 3 if AB  CD and A  C and B  D, then add the productions AB  XB, XB  XY, XY  CY CY  CD

Definition: Let G = (V, T, P, S) be a context-sensitive grammar and let w  T n for some n  1. Define a sequence of sets W i  (V  T) * as follows: W 0 = {S} for each i  0, W i+1 = W i  {   (V  T) + |    in G,  is in W i, and |  |  n}

Proposition: Let W i be as defined before. Then we have the following: 1) for each i  0, W i  W i+1 2) if W k = W k+1 for some k, W k = W k+m for all m > 0 3) for each i  0, W i = {   (V  T) * | S  m , |  |  n, m  i} 4) there exists k < max(2*|V  T| n, n+1) such that W k = W k+1 5) let k be the least integer such that W k = W k+1, then W k = {   (V  T) + | S  * , |  |  n}

Theorem: Let G = (V, T, P, S) be a context- sensitive grammar. Then there is an algorithm which, given any w  T *, decides whether or not w  L(G). (L(G) is recursive)