Benedict Kavanagh wrote: > In particular if wanted to write a left > recursive DCG grammar could I get eclipse to suspend identical recursive > calls and feed them with results as they come in as can be done with > OLDT resolution in systems like XSB, B-Prolog, and YapTab (extension to > Yap) Hi Ben, CHR's are good for chart parsing, which provides a natural way to deal with left-recursive grammars... Here's a toy example I wrote years ago in ECLiPSe. Cheers Mark -- Professor Mark Wallace Faculty of Information Technology Monash University, Caulfield Vic 3145, Australia Room 6.43, Building H Tel: +61 (0)3 9903 4276 % Chart Parser constraints s/3, vp/6, np/5, det/4, n/5, v/6, word/3, done/2. option(check_guard_bindings,off). bus([],End,End). bus([Word|Tail],N,End) :- M is N+1, word(Word,N,M), bus(Tail,M,End). word(the,H,T) <=> det(the,_,H,T). word(a,H,T) <=> det(a,sing,H,T). word(crook,H,T) <=> n(crook1,sing,physobj,H,T), n(crook2,sing,anim,H,T). word(servant,H,T) <=> n(servant,sing,anim,H,T). word(beckons,H,T) <=> v(beckon,sing,anim,anim,H,T). word(loves,H,T) <=> v(love,sing,anim,_,H,T). det(Det,Num1,Start,Mid),n(Noun,Num2,Type,Mid,End) ==> test_eq(Num1,Num2,Num3) | np((Det,Noun),Num3,Type,Start,End). v(Verb,Num,Type,OType1,Start,Mid),np(Obj,_Num2,OType2,Mid,End) ==> test_eq(OType1,OType2,_) | vp(Verb,Obj,Num,Type,Start,End). np(Subj,Num1,Type1,Start,Mid), vp(Verb,Obj,Num2,Type2,Mid,End) ==> test_eq(Type1,Type2,_), test_eq(Num1,Num2,_) | s(apply(Verb,Subj,Obj),Start,End). done(Start,End) \ s(Meaning,Start,End) <=> writeln(Meaning). chart_parse(Input) :- bus(Input,0,End), done(0,End). mytest2 :- chart_parse([the,crook,beckons,the,servant]). mytest3 :- chart_parse([the,servant,loves,the ,crook]). test_eq(X,Y,Z) :- not X\=Y, (nonvar(X)-> Z=X ; Z=Y). ECRC Common Logic Programming System [sepia kegi_xview opium megalog parallel] Version 3.5.1, Copyright ECRC GmbH, Mon Mar 6 17:43 1995 [eclipse 1]: lib(chr). yes. [eclipse 2]: chr(bup_grammar). yes. [eclipse 9]: chart_parse([the,pier,beckons,the,servant]). apply(beckon, (the, pier2), (the, servant)) Constraints: (2) det(the, _g626, 0, 1) (4) n(pier1, sing, physobj, 1, 2) (5) np((the, pier1), sing, physobj, 0, 2) (6) n(pier2, sing, anim, 1, 2) (7) np((the, pier2), sing, anim, 0, 2) (9) v(beckon, sing, anim, anim, 2, 3) (11) det(the, _g2170, 3, 4) (13) n(servant, sing, anim, 4, 5) (14) np((the, servant), sing, anim, 3, 5) (15) vp(beckon, (the, servant), sing, anim, 2, 5) (17) done(0, 5) yes. [eclipse 10]: chart_parse([the,servant,loves,the ,pier]). apply(love, (the, servant), (the, pier2)) apply(love, (the, servant), (the, pier1)) Constraints: (2) det(the, _g626, 0, 1) (4) n(servant, sing, anim, 1, 2) (5) np((the, servant), sing, anim, 0, 2) (7) v(love, sing, anim, _g1444, 2, 3) (9) det(the, _g1706, 3, 4) (11) n(pier1, sing, physobj, 4, 5) (12) np((the, pier1), sing, physobj, 3, 5) (13) vp(love, (the, pier1), sing, anim, 2, 5) (15) n(pier2, sing, anim, 4, 5) (16) np((the, pier2), sing, anim, 3, 5) (17) vp(love, (the, pier2), sing, anim, 2, 5) (19) done(0, 5) yes.Received on Mon Aug 24 2009 - 08:34:11 CEST
This archive was generated by hypermail 2.2.0 : Thu Feb 02 2012 - 02:31:58 CET