Definite Clause Grammar - Non-context-free Grammars

Non-context-free Grammars

In pure Prolog, normal DCG rules with no extra arguments on the functors, such as the previous example, can only express context-free grammars; there is only one argument on the left side of the production. However, context-sensitive grammars can also be expressed with DCGs, by providing extra arguments, such as in the following example:

s --> a(N), b(N), c(N). a(0) --> . a(M) -->, a(N), {M is N + 1}. b(0) --> . b(M) -->, b(N), {M is N + 1}. c(0) --> . c(M) -->, c(N), {M is N + 1}.

This set of DCG rules describes the grammar which generates the language that consists of strings of the form .

s --> symbols(Sem,a), symbols(Sem,b), symbols(Sem,c). symbols(end,_) --> . symbols(s(Sem),S) -->, symbols(Sem,S).

This set of DCG rules describes the grammar which generates the language that consists of strings of the form, by structurally representing

Read more about this topic:  Definite Clause Grammar

Famous quotes containing the word grammars:

    A sure proportion of rogue and dunce finds its way into every school and requires a cruel share of time, and the gentle teacher, who wished to be a Providence to youth, is grown a martinet, sore with suspicions; knows as much vice as the judge of a police court, and his love of learning is lost in the routine of grammars and books of elements.
    Ralph Waldo Emerson (1803–1882)