- 67 Views
- Uploaded on
- Presentation posted in: General

LING 388 Language and Computers

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

LING 388Language and Computers

Lecture 11

10/7/03

Sandiway FONG

- Computer Lab
- Double Class:
- Thursday 9th and Tuesday 14th

- Location:
- SBS 224

- Double Class:
- TA Office Hours
- Change in time and location
- Now Tuesdays after class 12:15 pm - 1:15 pm
- SBS 224

- Change in time and location

- Chomsky Hierarchy:
- Type-0 General rewrite rules
- Type-1 Context-sensitive rules
- anbncn
- Implementation: type-2 rules + counter
- Type-2 Context-free rules
- anbn
- Implementation: type-2 rules or type-3 rules + counter
- Type-3 Regular grammar rules
- a+b+
- Implementation: type-3 rules

- Type-0 General rewrite rules

- Production rule formats:
- Type-1:
- Next slide…
- Type-2:
- A -> a
- Type-3:
- A -> Bc A -> c or
- A -> cB A -> c

- Type-1:
- where …
- A e VN, c e VT and a e (VN u VT)*

- 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.
- Production rules have the format:
- a -> bsuch that |b| >= |a|

- where …
- a e (VN u VT)+
Note: a should not be comprised of just terminal symbols

- b e (VN u VT)*

- a e (VN u VT)+

- Production rules have the format:
- Notes:
- Length constraint means a rule like A -> l is not permitted

- (Almost equivalent) alternative definition:
- Production rules have the format:
- aAb -> agb

- where …
- A e VN
- a, b, g e (VN u VT)*

- Production rules have the format:
- Notes:
- a and b are “copied” over from the left to the right side unchanged
- a..b constitutes the (left and right) contexts for non-terminal A
- i.e. A -> g in context a__b

- However,
- … will be more convenient (for our purposes) to use the first definition

- Equivalence (informal)
- Can transform a context-sensitive rule of form:
- AB -> CD
- where A,B,C,D are all different non-terminals
into rules respecting the form:

- where A,B,C,D are all different non-terminals
- aAb -> agb

- AB -> CD

- Can transform a context-sensitive rule of form:
- Invent non-terminals A’ and B’
- Conversion:
- AB -> A’B(left context a empty, right context b = B)
- A’B -> A’B’(left context a = A’, right context b empty)
- A’B’ -> CB’(left context a empty, right context b = B’)
- CB’ -> CD(left context a = C, right context b empty)
- Note:
- All four rules respect aAb -> agb, yet clearly AB =>+ CD

- Example:
- Gabc is a type-1 grammar such that L(Gabc) = {anbncn | n >=1 }
- Gabc 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)

- Length restriction is respected

- Compare Gabc 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].

- How does Gabc work?
- Basic Idea:
- Gabc has two stages:
- Build an equal number of as, bs and cs
- Re-arrange them into the correct linear order

- Gabc has two stages:
- We have 4 production rules:
- S -> aSBcStage 1: Build
- S -> abc
- cB -> BcStage 2: Re-arrange
- bB -> bb

- Build Stage:
- S -> aSBc
- S -> abc

- Sentential Forms:
- S
- aSBcUsing 1st rule
- aaSBcBcUsing 1st rule
- aaabcBcBcUsing 2nd rule

- Notes:
- same number of as, bs (counting b and B together) and cs at each sentential form

- Re-arrangement Stage:
- cB -> Bc
- bB -> bb

- Example Sentential Form:
- aaabcBcBc

- Question: What can we do?
- 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

- Basic Idea 1: Re-arrange the order of Bs and cs
- Question: How do we know when to stop re-arranging?
- Answer:
- Basic Idea 2: Stop when a B comes into contact with a b

- Re-arrangement Stage:
- cB -> Bcre-arrange c and B
- bB -> bbstopping condition

- Example Sentential Form:
- aaabcBcBc

- 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:
- aaabcBcBc
- aaabBccBc
- aaabBcBcc
- aaabBBccc

- Re-arrangement Stage:
- cB -> Bcre-arrange c and B
- bB -> bbstopping condition

- Example Sentential Form:
- aaabBBccc

- We still have non-terminals in the sentential string
- so we’re not done yet

- Apply stopping condition:
- bB -> bb

- Example Derivation:
- aaabBBccc
- aaabbBccc
- aaabbbccc(a3b3c3)

- Final sentential form contains no non-terminals, so we’re done!

- Chomsky Hierarchy:
- Type-0 General rewrite rules
- Type-1 Context-sensitive rules
- anbncn
- Implementation: type-2 rules + counter or type-1 rules
- Type-2 Context-free rules
- anbn
- Implementation: type-2 rules or type-3 rules + counter
- Type-3 Regular grammar rules
- a+b+
- Implementation: type-3 rules

- Type-0 General rewrite rules

- General rewrite rule system
- Rule format:
- a -> b
- where
- a e (VN u VT)+
- b e (VN u VT)*

- Chomsky Hierarchy:
- Type-0 General rewrite rules
- Implementation: Turing Machine (TM)
- Type-1 Context-sensitive rules
- anbncn
- Implementation: Linear Bounded Automata (LBA)
- Type-2 Context-free rules
- anbn
- Implementation: Non-deterministic Push-Down Automata (NPDA)
- Type-3 Regular grammar rules
- a+b+
- Implementation: Finite State Automata (FSA)

- 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…

- DCG formalism is based on type-2 (context-free) grammars
- It is powerful enough to encode type-1 (context-sensitive) grammars
and beyond…

- Example:
- in Lecture 10, we exhibited a DCG for anbncn
- … based on type-2 rules plus a counter

- in Lecture 10, we exhibited a DCG for anbncn

- Example:

FSA

Regular

Expressions

Regular Grammars

=

Type-3

Type-2

Type-1

DCG = Type-0

- However, we cannot write DCG rules for context-sensitive rules directly
- Example:
- can’t write [c],b --> b, [c].
- for cB -> Bc

- Example:
- 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
- But before we leave …

- We now know
- {anbncn | n >=1 } is a context-sensitive (not context-free) language
- {anbn | n >=1 } is a context-free (not regular) language

- How about?
- Labcd = {anbncndn | n >=1 }

- Write a grammar for Labcd
- 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