A grammar is specified by setting the flag macro_expansion to on and by compiling clauses using the DCG operator -->.
[eclipse]: sh('cat gram.pl'). sentence --> noun_phrase, verb_phrase. noun_phrase --> article, noun. verb_phrase --> verb | verb, noun_phrase. article --> [the]. noun --> [compiler]. noun --> [program]. verb --> [compiles]. yes. [eclipse]: [gram]. /home/user/gram.pl compiled 732 bytes in 0.37 seconds yes. [eclipse]: phrase(sentence,[the,compiler,compiles]). yes. [eclipse]: phrase(sentence,[the,compiler,compiles,the,program]). yes. [eclipse]: phrase(sentence, X). X = [the, compiler, compiles] More? (;) X = [the, compiler, compiles, the, compiler] More? (;) X = [the, compiler, compiles, the, program] More? (;) X = [the, program, compiles] More? (;) X = [the, program, compiles, the, compiler] More? (;) X = [the, program, compiles, the, program] yes. [eclipse]: Fail: phrase(sentence, [not, a, sentence]). Error: phrase(X, [what, time, is, it]). (Error 4). phrase("sentence", X). (Error 5). phrase(123, X). (Error 5).