LING 388 Language and Computers Lecture 11 10/7/03 Sandiway FONG.

Slides:



Advertisements
Similar presentations
Natural Language Processing - Formal Language - (formal) Language (formal) Grammar.
Advertisements

C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 8: 9/29.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 7: 9/12.
LING 388 Language and Computers Lecture 8 9/25/03 Sandiway FONG.
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 6: 9/6.
PZ02A - Language translation
LING 388: Language and Computers Sandiway Fong Lecture 6: 9/13.
LING 388: Language and Computers Sandiway Fong Lecture 11: 10/3.
LING 388 Language and Computers Take-Home Final Examination 12/9/03 Sandiway FONG.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 12: 10/5.
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
LING 438/538 Computational Linguistics Sandiway Fong Lecture 5: 9/5.
LING 388 Language and Computers Lecture 9 9/30/03 Sandiway FONG.
Fall 2006Costas Busch - RPI1 The Chomsky Hierarchy.
A shorted version from: Anastasia Berdnikova & Denis Miretskiy.
Fall 2003Costas Busch - RPI1 Turing Machines (TMs) Linear Bounded Automata (LBAs)
PZ03A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ03A - Pushdown automata Programming Language Design.
Finite State Machines Data Structures and Algorithms for Information Processing 1.
LING 388 Language and Computers Lecture 6 9/18/03 Sandiway FONG.
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.
::ICS 804:: Theory of Computation - Ibrahim Otieno SCI/ICT Building Rm. G15.
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.
Context Free Grammars CIS 361. Introduction Finite Automata accept all regular languages and only regular languages Many simple languages are non regular:
1 Computability Five lectures. Slides available from my web page There is some formality, but it is gentle,
Introduction to Language Theory
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 α 
Parsing Introduction Syntactic Analysis I. Parsing Introduction 2 The Role of the Parser The Syntactic Analyzer, or Parser, is the heart of the front.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 11 Midterm Exam 2 -Context-Free Languages Mälardalen University 2005.
1 Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
9.7: Chomsky Hierarchy.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
PZ03A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ03A - Pushdown automata Programming Language Design.
LING/C SC/PSYC 438/538 Lecture 15 Sandiway Fong. Did you install SWI Prolog?
Discrete Structures ICS252 Chapter 5 Lecture 2. Languages and Grammars prepared By sabiha begum.
1 Turing Machines and Equivalent Models Section 13.1 Turing Machines.
98 Nondeterministic Automata vs Deterministic Automata We learned that NFA is a convenient model for showing the relationships among regular grammars,
Week 14 - Friday.  What did we talk about last time?  Simplifying FSAs  Quotient automata.
CS6800 Advance Theory of Computation Spring 2016 Nasser Alsaedi
LING/C SC/PSYC 438/538 Lecture 17 Sandiway Fong. Last Time Talked about: – 1. Declarative (logical) reading of grammar rules – 2. Prolog query: s(String,[]).
Modeling Arithmetic, Computation, and Languages Mathematical Structures for Computer Science Chapter 8 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesAlgebraic.
Formal Languages, Automata and Models of Computation
Linear Bounded Automata LBAs
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Language and Grammar classes
Complexity and Computability Theory I
Natural Language Processing - Formal Language -
Context Sensitive Languages and Linear Bounded Automata
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
The chomsky hierarchy Module 03.3 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Context free grammar.
PARSE TREES.
PZ03A - Pushdown automata
LING/C SC/PSYC 438/538 Lecture 17 Sandiway Fong.
Course 2 Introduction to Formal Languages and Automata Theory (part 2)
CSE322 The Chomsky Hierarchy
Jaya Krishna, M.Tech, Assistant Professor
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
The Chomsky Hierarchy Costas Busch - LSU.
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Pushdown automata Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Presentation transcript:

LING 388 Language and Computers Lecture 11 10/7/03 Sandiway FONG

Administrivia Computer Lab Computer Lab  Double Class:  Thursday 9th and Tuesday 14th  Location:  SBS 224 TA Office Hours TA Office Hours  Change in time and location  Now Tuesdays after class 12:15 pm - 1:15 pm  SBS 224

Review Chomsky Hierarchy: Chomsky Hierarchy:  Type-0 General rewrite rules  Type-1 Context-sensitive rules  a n b n c n  Implementation: type-2 rules + counter Type-2 Context-free rulesType-2 Context-free rules a n b n a n b n Implementation: type-2 rules or type-3 rules + counter Implementation: type-2 rules or type-3 rules + counter –Type-3 Regular grammar rules – a + b + – Implementation: type-3 rules

Review Production rule formats: Production rule formats:  Type-1:  Next slide…  Type-2: A -> A ->  Type-3:Type-3: –A -> Bc A -> c or –A -> cB A -> c where … where …  A  V N, c  V T and  (V N u V T ) *

Context-sensitive Grammars Type-2 and 3 grammars may only have a single non- terminal on the left. Type-2 and 3 grammars may only have a single non- terminal on the left. Type-1 (context-sensitive) grammars extend what’s allowed on the left. Type-1 (context-sensitive) grammars extend what’s allowed on the left.  Production rules have the format:   ->  such that |  | >= |  |  where …   (V N u V T ) + Note:  should not be comprised of just terminal symbols   (V N u V T ) * Notes: Notes:  Length constraint means a rule like A -> is not permitted

Context-sensitive Grammars (Almost equivalent) alternative definition: (Almost equivalent) alternative definition:  Production rules have the format:   ->   where …   V N   (V N u V T ) * Notes: Notes:   and  are “copied” over from the left to the right side unchanged   constitutes the (left and right) contexts for non-terminal A  i.e. A ->  in context  However, However,  … will be more convenient (for our purposes) to use the first definition

Context-sensitive Grammars Equivalence (informal) Equivalence (informal)  Can transform a context-sensitive rule of form:  AB -> CD where A,B,C,D are all different non-terminalswhere A,B,C,D are all different non-terminals into rules respecting the form:   ->  Invent non-terminals A’ and B’ Invent non-terminals A’ and B’ Conversion: Conversion:  AB -> A’B(left context  empty, right context  = B)  A’B -> A’B’(left context  = A’, right context  empty)  A’B’ -> CB’(left context  empty, right context  = B’)  CB’ -> CD(left context  = C, right context  empty)  Note:  All four rules respect  ->  yet clearly AB => + CD

Context-sensitive Grammars Example: Example:  G abc is a type-1 grammar such that L(G abc ) = {a n b n c n | n >=1 }  G abc has 4 production rules:  S -> aSBc  S -> abc  cB -> Bc  bB -> bb  Notes:  1st two rules context-free  3rd/4th rules context-sensitive c (resp. b) left context for non-terminal B in cB -> Bc (bB -> bb)c (resp. b) left context for non-terminal B in cB -> Bc (bB -> bb)  Length restriction is respected

Context-sensitive Grammars Compare G abc to DCG (based on type-2 rules) shown in Lecture 10: Compare G abc to DCG (based on type-2 rules) shown in Lecture 10:  s --> [a],t(1),[c].  t(N) --> [a],{M is N+1},t(M),[c].  t(N) --> u(N).  u(N) --> {N > 1}, [b],{M is N-1},u(M).  u(1) --> [b].

Context-sensitive Grammars How does G abc work? How does G abc work? Basic Idea: Basic Idea:  G abc has two stages: 1. Build an equal number of as, bs and cs 2. Re-arrange them into the correct linear order We have 4 production rules: We have 4 production rules:  S -> aSBcStage 1: Build  S -> abc  cB -> BcStage 2: Re-arrange  bB -> bb

Context-sensitive Grammars Build Stage: Build Stage:  S -> aSBc  S -> abc Sentential Forms: Sentential Forms:  S  aSBcUsing 1st rule  aaSBcBcUsing 1st rule  aaabcBcBcUsing 2nd rule Notes: Notes:  same number of as, bs (counting b and B together) and cs at each sentential form

Context-sensitive Grammars Re-arrangement Stage: Re-arrangement Stage:  cB -> Bc  bB -> bb Example Sentential Form: Example Sentential Form:  aaabcBcBc Question: What can we do? Question: What can we do? Answer: Answer:  Basic Idea 1: Re-arrange the order of Bs and cs  want to move the Bs to the left  want to move the cs to the right Question: How do we know when to stop re-arranging? Question: How do we know when to stop re-arranging? Answer: Answer:  Basic Idea 2: Stop when a B comes into contact with a b

Context-sensitive Grammars Re-arrangement Stage: Re-arrangement Stage:  cB -> Bcre-arrange c and B  bB -> bb stopping condition Example Sentential Form: Example Sentential Form:  aaabcBcBc Basic Idea 1: Re-arrange the order of Bs and cs Basic Idea 1: Re-arrange the order of Bs and cs  cB -> Bc  “If a c precedes a B, the order is wrong, let’s flip them” Example of Derivation: Example of Derivation:  aaabcBcBc  aaabBccBc  aaabBcBcc  aaabBBccc

Context-sensitive Grammars Re-arrangement Stage: Re-arrangement Stage:  cB -> Bcre-arrange c and B  bB -> bb stopping condition Example Sentential Form: Example Sentential Form:  aaabBBccc We still have non-terminals in the sentential string We still have non-terminals in the sentential string  so we’re not done yet Apply stopping condition: Apply stopping condition:  bB -> bb Example Derivation: Example Derivation:  aaabBBccc  aaabbBccc  aaabbbccc(a 3 b 3 c 3 ) Final sentential form contains no non-terminals, so we’re done! Final sentential form contains no non-terminals, so we’re done!

Grammar Rule Implementations Chomsky Hierarchy: Chomsky Hierarchy:  Type-0 General rewrite rules  Type-1 Context-sensitive rules  a n b n c n  Implementation: type-2 rules + counter or type-1 rules Type-2 Context-free rulesType-2 Context-free rules a n b n a n b n Implementation: type-2 rules or type-3 rules + counter Implementation: type-2 rules or type-3 rules + counter –Type-3 Regular grammar rules – a + b + – Implementation: type-3 rules

Type-0 Grammars General rewrite rule system General rewrite rule system Rule format: Rule format:   ->   where   (V N u V T ) +   (V N u V T ) *

Equivalent Automata Implementations Chomsky Hierarchy: Chomsky Hierarchy:  Type-0 General rewrite rules  Implementation: Turing Machine (TM)  Type-1 Context-sensitive rules  a n b n c n  Implementation: Linear Bounded Automata (LBA) Type-2 Context-free rulesType-2 Context-free rules a n b n a n b n Implementation: Non-deterministic Push-Down Automata (NPDA) Implementation: Non-deterministic Push-Down Automata (NPDA) –Type-3 Regular grammar rules – a + b + – Implementation: Finite State Automata (FSA)

Equivalent Automata Implementations Machine Characteristics: Machine Characteristics:  All the machine types have a finite state core  However, they differ with respect to working memory  The difference in expressive power can be traced to limitations on the working memory…

Equivalent Automata Implementations Grammar Working Memory Notes Type-3None Type-2Stack Push/Pop operations No limit on size of stack Type-1Tape Write/(Erase)/Read Move (read head) left/right Length limited to a linear function of the input length Type-0Tape Write/(Erase)/Read Move (read head) left/right Unlimited length

DCG and Context-sensitive Grammars DCG formalism is based on type-2 (context-free) grammars DCG formalism is based on type-2 (context-free) grammars It is powerful enough to encode type-1 (context- sensitive) grammars It is powerful enough to encode type-1 (context- sensitive) grammars and beyond…  Example:  in Lecture 10, we exhibited a DCG for a n b n c n … based on type-2 rules plus a counter… based on type-2 rules plus a counter

DCG and Chomsky Hierarchy Regular Grammars = Type-3 FSA Regular Expressions DCG = Type-0 Type-2 Type-1

DCG and Context-sensitive Grammars However, we cannot write DCG rules for context-sensitive rules directly However, we cannot write DCG rules for context-sensitive rules directly  Example:  can’t write [c],b --> b, [c].  for cB -> Bc Note: Note:  we can write Prolog code that takes a context-sensitive grammar and interprets it  Possible term programming project?

This concludes our tour of the grammar hierarchy for this course This concludes our tour of the grammar hierarchy for this course But before we leave … But before we leave …

Extra Credit Homework Question We now know We now know  {a n b n c n | n >=1 } is a context-sensitive (not context- free) language  {a n b n | n >=1 } is a context-free (not regular) language How about? How about?  L abcd = {a n b n c n d n | n >=1 } Write a grammar for L abcd Write a grammar for L abcd Notes: Notes:  Not a computer lab homework  Extra credit question is entirely optional  A chance to make up some ground if you lost points on Homeworks 1 or 2  Hand in your solution at the same time as Homework 3