DCG problem
DCG problem
(OP)
I have to write a DCG that generates strings from the alphabet a E {0,1,2} the strings have to have the form nn. This means queries like ?- s([0,2,1,0,2,1],[]). and s([1,1,2,0,1,1,2,0],[]). would return true.
This is the code I have so far. I'm so close. Can someone help me further?
s --> s(X), s(X).
s --> [].
s(0) --> zero, s(X).
s(1) --> one, s(X).
s(2) --> two, s(X).
s(3) --> [].
zero --> [0].
one --> [1].
two --> [2].
Many thanks ;)
This is the code I have so far. I'm so close. Can someone help me further?
s --> s(X), s(X).
s --> [].
s(0) --> zero, s(X).
s(1) --> one, s(X).
s(2) --> two, s(X).
s(3) --> [].
zero --> [0].
one --> [1].
two --> [2].
Many thanks ;)
RE: DCG problem
CODE
s --> sx, s.
sx --> [0].
sx --> [1].
sx --> [2].
RE: DCG problem
Just look at these rules
s --> s(X), s(X).
and
s(0) --> zero, s(X).
In the first rule, what is the type of X, an atom or a list ?
In the second rule you use an atom 0, and you introduce X in the body of the rule. You don't have a lot of things to change/add.
RE: DCG problem
RE: DCG problem