This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/Logtalk/examples/dcgs/parsetree.lgt

30 lines
520 B
Plaintext
Raw Normal View History

:- object(parsetree,
implements(parsep)).
parse(List, Tree) :-
phrase(sentence(Tree), List).
sentence(s(NP,VP)) --> noun_phrase(NP), verb_phrase(VP).
noun_phrase(np(D,NP)) --> determiner(D), noun(NP).
noun_phrase(NP) --> noun(NP).
verb_phrase(vp(V)) --> verb(V).
verb_phrase(vp(V,NP)) --> verb(V), noun_phrase(NP).
determiner(d(the)) --> [the].
determiner(d(a)) --> [a].
noun(n(boy)) --> [boy].
noun(n(girl)) --> [girl].
verb(v(likes)) --> [likes].
verb(v(hates)) --> [hates].
:- end_object.