Title: CS 603: Programming Languages
1CS 603 Programming Languages
- Lecture 28
- Spring 2004
- Department of Computer Science
- University of Alabama
- Joel Jones
2Overview
- More about Definite Clause Grammars
- Adding arguments
- Building parse trees
3More on Definite Clause Grammars
- Taken from
- http//www.coli.uni-sb.de/kris/prolog-course/html
/node66.html - The grammar from last time didnt handle
pronouns, so how do we fix it? - Extend the grammar -or-
- Use additional arguments
4New Sentence DCG
- Add pronouns to support sentences like
- She shoots him and He shoots her
s --gt np,vp. np --gt det,n. np --gt
pro. vp --gt v,np. vp --gt v. det --gt the.
det --gt a. n --gt woman. n --gt man.
v --gt shoots. pro --gt he. pro ---gt
she. pro --gt him. pro --gt her.
s --gt np,vp. np --gt det,n. vp --gt v,np.
vp --gt v. det --gt the. det --gt a.
n --gt woman. n --gt man. v --gt shoots.
Becomes
5Fixing Sentence DCG
- Accepts incorrect sentences, such as
- A woman shoots she, Her shoots she
- Problem is there is no encoding of subject
pronouns, such she and he or of object
pronouns, such as her and his - We can fix this with new rules
6Pronouns using Rules
s --gt np_subject,vp. np_subject --gt det,n. np_obj
ect --gt det,n. np_subject --gt pro_subject. np_obj
ect --gt pro_object. vp --gt v,np_object.
vp --gt v. det --gt the. det --gt a.
n --gt woman. n --gt man. v --gt shoots.
pro_subject --gt he. pro_object --gt
him. pro_subject ---gt she. pro_object --gt
her.
7Pronouns using Arguments
s --gt np(subject),vp. np(_) --gt det,n. np(X) --gt
pro(X). vp --gt v,np(object). vp --gt v.
det --gt the. det --gt a. n --gt woman.
n --gt man. v --gt shoots. pro(subject) --gt
he. pro(object) --gt him. pro(subject) ---gt
she. pro(object) --gt her.
8DCG Argument Implementation
s(A,B)Â - np(A,C), vp(C,B).
Is syntactic sugar for
s --gt np,vp.
And
s(A,B)Â - np(subject,A,C), vp(C,B).
Is syntactic sugar for
s --gt np(subject),vp.
np(A,B,C)Â - det(B,D), n(D,C). np(A,B,C)Â
- pro(A,B,C.
Is syntactic sugar for
np(_) --gt det,n. np(X) --gt pro(X).
9New Sentence DCG at Work
? np(X,NP,). X  _2625 NP  the,woman  X Â
_2625 NP  the,man  X  _2625 NP  a,womanÂ
 X  _2625 NP  a,manÂ
X  subject  NP  he  X  subject Â
NP  she  X  object  NP  himÂ
 X  object  NP  her  no
10Building Parse Trees
- How do we represent and build a parse tree?
- In other words, for the tree below on the left,
produce the term below on the right.
s(np(det(a), n(woman), vp(v(shoots),
np(det(a), n(man))).
11Building Parse Trees (cont.)
s(s(NP,VP)) --gt np(NP), vp(VP).
np(np(DET,N)) --gt det(DET),
n(N). vp(vp(V,NP)) --gt v(V),
np(NP). vp(vp(V))    --gt v(V).
det(det(the)) --gt the. det(det(a))   --gt a.
n(n(woman)) --gt woman. n(n(man))   --gt man.
v(v(shoots)) --gt shoots.
12DCGs for non-CFGs
- Consider the formal language
- anbncn - e which consists of all non-null strings
which consist of n as followed by n bs
followed by n cs
13DCGs for non-CFGs (cont.)
s(Count) --gt ablock(Count),
bblock(Count), cblock(Count).
ablock(0) --gt . ablock(succ(Count)) --gt a,ab
lock(Count). bblock(0) --gt .
bblock(succ(Count)) --gt b,bblock(Count).
cblock(0) --gt . cblock(succ(Count)) --gt c,cb
lock(Count).
14DCGs for non-CFGs Example
?- s(Count,L,). Count 0 L Count
succ(0) L a, b, c Count succ(succ(0)) L
a, a, b, b, c, c Count
succ(succ(succ(0))) L a, a, a, b, b, b, c, c,
c