Prolog parsing is running out of stack -
i have code
s(w) :- append(w1,w2,w), np(w1), vp(w2). vp(w) :- append(w1,w2,w), v(w1), np(w2). np(w) :- ( append(w1,w2,w), pn(w1), ph(w2) ; append(w1,w2,w), det(w1), n(w2) ). pn([hans]). ph([]). v([beobachtet]). n([mann]). n([fernrohr]). p([mit]). det([den]). det([dem]).
when cast np(x).
vp(x).
or pp(x)
1 possible parse , out of stack error. when cast s(x).
don't parse. know because there infinite loop running, cant point out @ point gets looped. figured might happen because of using same names variables, changed them individual ones , didn't alter anything.
any 1 got hint?
thanks in advance!
reason out of stack
let's @ next line code:
vp(w) :- append(w1,w2,w), v(w1), np(w2).
running append(w1, w2, w)
in isolation gives following:
?- append(w1, w2, w). w1 = [], w2 = w ; w1 = [_g1108], w = [_g1108|w2] ; w1 = [_g1108, _g1114], w = [_g1108, _g1114|w2] ; w1 = [_g1108, _g1114, _g1120], w = [_g1108, _g1114, _g1120|w2] .
as can see, w1
list of increasing length. length 1 give solution (since v(w1)
). after first instantiation, w1
gets longer , longer , longer , ..., v(w1)
not succeed lists of longer length.
in prolog can utilize dcg notation create grammar. grammar follows:
s --> np, vp. np --> pn. np --> det, n. vp --> v, np. det --> [den]. det --> [dem]. n --> [mann]. n --> [fernrohr]. pn --> [hans]. v --> [beobachtet].
example of use ?- phrase(s, s). s = [hans, beobachtet, hans] ; s = [hans, beobachtet, den, mann] ; s = [hans, beobachtet, den, fernrohr] ; s = [hans, beobachtet, dem, mann] ; s = [hans, beobachtet, dem, fernrohr] ; s = [den, mann, beobachtet, hans] ; s = [den, mann, beobachtet, den, mann] ; s = [den, mann, beobachtet, den, fernrohr] ; s = [den, mann, beobachtet, dem, mann] ; s = [den, mann, beobachtet, dem, fernrohr] ; s = [den, fernrohr, beobachtet, hans] ; s = [den, fernrohr, beobachtet, den, mann] ; s = [den, fernrohr, beobachtet, den, fernrohr] ; s = [den, fernrohr, beobachtet, dem, mann] ; s = [den, fernrohr, beobachtet, dem, fernrohr] ; s = [dem, mann, beobachtet, hans] ; s = [dem, mann, beobachtet, den, mann] ; s = [dem, mann, beobachtet, den, fernrohr] ; s = [dem, mann, beobachtet, dem, mann] ; s = [dem, mann, beobachtet, dem, fernrohr] ; s = [dem, fernrohr, beobachtet, hans] ; s = [dem, fernrohr, beobachtet, den, mann] ; s = [dem, fernrohr, beobachtet, den, fernrohr] ; s = [dem, fernrohr, beobachtet, dem, mann] ; s = [dem, fernrohr, beobachtet, dem, fernrohr].
parsing prolog dcg failure-slice non-termination
No comments:
Post a Comment