I am trying to work out this simple DCG assignment (Prolog) for my course. The prblem is about creating a DCG. I have already defined a Universe of Discourse in my code. But this question is a bit misleading to me. According to what I've read and know, using my own notes and this Learn Prolog Now! - LINK: http://www.learnprolognow.org/lpnpage.php?pagetype=html&pageid=lpn-htmlse29
One can construct a DCG with (a^nb^nc^n). Where a b and c are normal letters and n is the number the letter is to be multiplied with. However, my question is like this.
"Design and implement a DCG to recognize (or generate) the language 0n1n0n."
Can somebody please help me out here? What is exactly wanted by the question?
With regards to one of the answers, I have tried the following code with no luck.
s --> [].
s(M) --> a(M),b(M),c(M).
a --> [].
a(New) --> [0], a(Cnt),{New is Cnt+1}.
b --> [].
b(New) --> [1], b(Cnt),{New is Cnt+1}.
c --> [].
c(New) --> [0], c(Cnt),{New is Cnt+1}.
count(T, N) --> [0,1,0], count(T, M), {N is M+1}.
count(_, 0) --> [].
s --> [].is useless.a --> [].should bea(0) --> []., etc etc. As I posted in EDIT section, these changes will be needed also for the generative part. - CapelliC