Skip to content

Instantly share code, notes, and snippets.

@jahan-addison
Last active May 10, 2020 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jahan-addison/8914c02cf248310ab08c65a966470d31 to your computer and use it in GitHub Desktop.
Save jahan-addison/8914c02cf248310ab08c65a966470d31 to your computer and use it in GitHub Desktop.
-- https://en.wikipedia.org/wiki/Definite_clause_grammar
-- http://cs.union.edu/~striegnk/learn-prolog-now/html/node59.html#subsec.l7.firstexample
-- This grammar allows sentences like "he likes her" and "he likes him", but not "her likes he" and "him likes him".
sentence --> pronoun(subject), verb_phrase.
verb_phrase --> verb, pronoun(object).
pronoun(subject) --> [he].
pronoun(subject) --> [she].
pronoun(object) --> [him].
pronoun(object) --> [her].
verb --> [likes].
-- "the bat eats a cat"
sentence(s(NP,VP)) --> noun_phrase(NP), verb_phrase(VP).
noun_phrase(np(D,N)) --> det(D), noun(N).
verb_phrase(vp(V,NP)) --> verb(V), noun_phrase(NP).
det(d(the)) --> [the].
det(d(a)) --> [a].
noun(n(bat)) --> [bat].
noun(n(cat)) --> [cat].
verb(v(eats)) --> [eats]
----
s --> simple_s.
s --> simple_s conj s.
simple_s --> np,vp.
np --> det,n.
vp --> v,np.
vp --> v.
det --> [the].
det --> [a].
n --> [woman].
n --> [man].
v --> [shoots].
conj --> [and].
conj --> [or].
conj --> [but].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment